[jdom-interest] Problems by parsing XML with JDOM

Edelson, Justin Justin.Edelson at mtvn.com
Tue Apr 11 07:17:28 PDT 2006


Because your elements are in the http://www.ebi.ac.uk/schema, you need to pass a Namespace object to getChild().

See: http://jdom.org/docs/faq.html#a0260

-----Original Message-----
From: jdom-interest-bounces at jdom.org [mailto:jdom-interest-bounces at jdom.org] On Behalf Of ajoecker at freenet.de
Sent: Tuesday, April 11, 2006 9:49 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] Problems by parsing XML with JDOM

Hello,
I like to parse a XML document with JDOM. I get the root element without problems, but no child elements. I hope someone can tell me what I do wrong.
Thanks,Anika
Here is my code:
SAXBuilder builder = new SAXBuilder(); Document doc = null;                 doc = builder.build(new StringReader(xml));Element root = doc.getRootElement();System.out.println(root.getName());Element header = root.getChild("Header"); Element program = header.getChild("program"); System.out.println(program.getAttributeValue("name")); <- Here I get a NullPointerExeption, because the variable program is empty

And here is my XML code:
<?xml version="1.0"?><EBIApplicationResult xmlns="http://www.ebi.ac.uk/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ebi.ac.uk/schema/ApplicationResult.xsd"><Header>        <program name="WU-blastp" version="2.0MP-WashU [01-Jan-2006]" citation="PMID:12824421"/>        <parameters>                <sequences total="1">                        <sequence number="1" name="Sequence" type="p" length="39"/>                </sequences>                <databases total="1" sequences="2966745" letters="967946558">                        <database number="1" name="uniprot" type="p" created="2006-04-04T00:57:47+01:00"/>                </databases>                <scores>100</scores>                <alignments>50</alignments>                <matrix>BLOSUM62</matrix>                <expectationUpper>1</expectationUpper>                <statistics>sump</statistics>        </parameters>        <timeInfo start="2006-04-11T11:15:36+01:00"!
  end="2006-04-11T11:15:41+01:00" search="PT05S"/></Header></EBIApplicationResult>
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list