[jdom-interest] Accessing Child Elements

Rodney Sonderegger rodney.sonderegger at incaparc.ch
Tue Sep 5 11:20:07 PDT 2000


Hello

we're testing JDOM in our application and I found some strange things,
which I can't explain.
I'm using the SAXBuilder to read the Streamdata passed by the Database
(Tamino):
-------------------------------------------------------------------
  <?xml version="1.0" encoding="utf-8" ?>
 <ino:response
xmlns:ino="http://namespaces.softwareag.com/tamino/response2"
xmlns:xql="http://metalab.unc.edu/xql/">
  <xql:query>Profile[ProviderKey="0011" and
Application="eRetail"]</xql:query>
 <ino:message ino:returnvalue="0">
  <ino:messageline>XQL Request processing</ino:messageline>
  </ino:message>
 <xql:result>
 <Profile ino:id="2">
  <Application>eRetail</Application>
  <ProviderKey>0011</ProviderKey>
  <DefaultLanguage>de</DefaultLanguage>
  <DefaultPriority>1</DefaultPriority>
  <URLPrefix>www.yellowgate.ch/cgi-bin/ygate/yellowgate</URLPrefix>
  <InfoKeySequence>5</InfoKeySequence>
  </Profile>
  </xql:result>
 <ino:cursor ino:count="1">
  <ino:first ino:href="?_XQL(1,16)=Profile[ProviderKey="0011" and
Application="eRetail"]" />
  </ino:cursor>
 <ino:message ino:returnvalue="0">
  <ino:messageline>XQL Request processed</ino:messageline>
  </ino:message>
  </ino:response>
----------------------------


The Parser works fine and parses the document without errors.
I'm interested in the <Profile> Element and try to get it with:

      Element root = aDoc.getRootElement();
      Element xmlProfile = root.getChild("result").getChild("Profile");

I get an NULL Pointerexception trying to do that.
when I  run an Iterator:

    Iterator anIt = root.getChildren().iterator();
      while (anIt.hasNext()){
        Element aElem = (Element) anIt.next();
        if (aElem.getName().equals("result")){
          xmlProfile = aElem;
          ......
        }
      }

then I can access the subelements of <result> does anybody know why this

is the case??

Thanx & Regards
Rodney



More information about the jdom-interest mailing list