[jdom-interest] getChildren() returns an empty list.. (please
help)
John L. Webber - Jentro AG
John.Webber at jentro.com
Tue Oct 22 06:29:37 PDT 2002
Mirabito, Massimo wrote:
> You will have to forgive me but I am extremely new to JDOM.
Hope you enjoy JDOM!
> Following is a summary of my problem
>
> 1) XML document
> <?xml version="1.0" encoding="UTF-8"?>
> <security xmlns="s2">
> <application>
> <application-id>100</application-id>
> <application-name>Application 1</application-name>
> <application-description>Application 1
> Description</application-description>
> <application-roles>
> <role id="1" name="Role 1" description="Role 1 Desc" />
> <role id="2" name="Role 2" description="Role 2 Desc" />
> </application-roles>
> </application>
> <user-roles>
> <role id="1" name="Role 1" description="Role 1 Desc">
> <access id="1" name="can">111111</access>
> </role>
> <role id="2" name="Role 2" description="Role 2 Desc">
> <access id="2" name="irb_id">4444444</access>
> </role>
> </user-roles>
> </security>
>
> 3) I can get the root element I check and see if it has children and it
> returns true.... but when I invoke getChildren() the List size is 0
>
> root = doc.getRootElement();
> System.out.println("has children " + root.hasChildren());
> List appRoles = root.getChildren("application-roles ");
> System.out.println("Size " + appRoles.size());
Look at the javadocs for Element.getChildren(String) carefully: "This
returns a List of all the child elements nested directly (one level
deep) within this element with the given local name and belonging to no
namespace, returned as Element objects."
That is why root.hasChildren() returns true, but
root.getChildren("application-roles") returns an empty List: the
<application-roles> element is not nested directly under the root element.
In general, JDOM methods that return lists return an empty list on
failure, not null.
Greetings,
John
--
---------------------------------------------------------
Jentro AG
John L. Webber, Software Development
---------------------------------------------------------
Peter-Henlein-Strasse 28, 85540 Haar/Munich, Germany
Tel. +49 89 462 385 0 mailto:John.Webber at jentro.com
Fax +49 89 462 385 29 http://www.jentro.com
---------------------------------------------------------
{ smart networks - connect your world }
---------------------------------------------------------
More information about the jdom-interest
mailing list