SV: [jdom-interest] getChildren more one level deep

Per Norrman pernorrman at telia.com
Tue May 20 14:02:01 PDT 2003


Hi,

you can't! However, using XPath will save you lots of code:

public class Nonsense
{
	public static void main(String[] args) throws Exception
	{
		SAXBuilder builder =3D new SAXBuilder();

		//  Read the document with any convenient method  ...
		Document doc =3D builder.build(...);
       =20
        	XPath p =3D XPath.newInstance("//el");
        	for (Iterator i =3D p.selectNodes(doc).iterator(); =
i.hasNext();)
		{
            	Element e =3D (Element) i.next();
            	System.out.println(e.getTextTrim());
		}
	}
}

A thorough study of XPath will probably pay off!

/pmn


> -----Ursprungligt meddelande-----
> Fr=C3=A5n: jdom-interest-admin at jdom.org=20
> [mailto:jdom-interest-admin at jdom.org] F=C3=B6r Antonello Dell'Armi
> Skickat: den 20 maj 2003 14:12
> Till: jdom-interest at jdom.org
> =C3=84mne: [jdom-interest] getChildren more one level deep
>=20
>=20
> =20
>=20
> 	If i have:
> 	=20
> 	<root>
> 	<status>
> 	      <el>
> 	              VALUE
> 	      </el>
> 	      <el>=20
> 	              VALUE2
> 	      </el>
> 	</status>
> 	</root>
> 	=20
> 	How can i retrieve the VALUE (content of el Element)=20
> without passing through element status?
> 	=20
> 	root.getChildren(''el'') seems doens't work....
> 	=20
> 	BRGS
> 	@nto
>=20
>                   '=CA=B6%=CA=8B& )z=ED=B7=ACgm * i  l  X{ =
Y=EA=9A=9F)*' =DD=A2o z=7F ik *.=1A,(
>=20




More information about the jdom-interest mailing list