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

Malachi de AElfweald malachi at tremerechantry.com
Tue Oct 22 10:08:40 PDT 2002


A couple questions.

1)  Are you saying that List.size() returns 0 elements, but List.iterator() iterates through them?
2)  Do you get the same results if you take out the xmlns="s2"?
3)  XML design question here. Why have terms "application-id" inside "application"? Any tag inside
the "application" tag is assumed to be part of the "application" structure.  It would look cleaner
to either change that to an "id"/"name"/"description" tag, or make them attributes of the 
"application" tag.  Generally, descriptions should be their own tag, using CDATA as well to allow any 
kind of comment....

Malachi


10/22/2002 5:43:21 AM, "Mirabito, Massimo" <mcm8 at cdc.gov> wrote:

>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
>
>
>_______________________________________________
>To control your jdom-interest membership:
>http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
>
>






More information about the jdom-interest mailing list