[jdom-interest] getChildren() returns an empty list.. (please help)

Mirabito, Massimo mcm8 at cdc.gov
Tue Oct 22 05:43:21 PDT 2002


You will have to forgive me but I am extremely new to JDOM. I have been
struggling with  this particular problem for a day now and I cannot figure
it out.

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>

2) I load it into JDOM in the following manner

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new StringReader(xml));


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());	


4) However I can process all elements in the document with no problem with
the following function

private void processElement(Element e) {
  List list = e.getChildren();
  Iterator i = list.iterator();
   while (i.hasNext()) {
    Element element = (Element) i.next();
    System.out.println(list.size() + " ***" + element.getName() + " - " +
    element.getAttributeValue("id") + " - " + 
    element.getAttributeValue("name") + " - " + 
    element.getAttributeValue("description") + " - " + 
    element.getText().trim()   );
    processElement (element);
  }
}

What Am I doing wrong?

Thanks in advance for any help

Max





More information about the jdom-interest mailing list