[jdom-interest] Element.getChildren(java.lang.String name)?

Gary Bentley gb at opengroup.org
Wed Mar 7 05:16:28 PST 2001


If you are trying to find the "element" element...then you need to dig one
level down...

Element root = doc.getRootElement ("complexType");
Element el = root.getChild ("sequence").getChild ("element");

If you are using getChildren that will return a List of elements...
In that case you have to index into the List and get the element you want...

List children = root.getChildren ("sequence");
Element firstchild = (Element) children.get (0);
Element el = firstchild.getChild ("element");

Remember to check for null for the children List.

It may also be a naming problem...i.e. you could have spelled something
incorrectly...

To get around that I use static final variables...

i.e.

public class XMLDefs
{

    static public final String complexType = "complexType";

}

Then use it:

Element root = doc.getRootElement (XMLDefs.complexType);

That way the compiler will tell you if you are wrong...
It's a bit of an overhead but saves a lot of time for other problems...

G.

-----Original Message-----
From: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]On Behalf Of Paul Simon Barriscale
Sent: Wednesday, March 07, 2001 12:53 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] Element.getChildren(java.lang.String name)?


I'm having trouble accessing the the children of a specific element.
this is a fragment of the XML

<complexType name="RepositoryType">
	<sequence>
		<element name="IRObject" type="IRObjectType"/>
		...
		...
	</sequence>
</complexType>

by when I call Element.getChildren(complexType) it does not find this
element.
Am i calling this method incorrectly? any help is appreciated.

Regards,
Paul



--
Paul Barriscale
barrisca at student.cs.ucc.ie    http://student.cs.ucc.ie/01/barrisca
_______________________________________________________
University College Cork
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com




More information about the jdom-interest mailing list