[jdom-interest] Building with Namespaces
Steve Beech
JBeech at dmu.ac.uk
Fri Jun 27 06:06:40 PDT 2003
All,
I have the following doc and need to get at the content in the
'myThirdElement' element
<?xml version="1.0" encoding="UTF-8"?>
<myRootElement xmlns="http://www.myserver/mynamespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.myserver/myxsinamespace
http://www.myserver/schemas/myxsinamespace.xsd">
<xy:mySecondElement xmlns:xy="http://www.myserver/anothernamespace"
xsi:schemaLocation="http://www.myserver/anotherxsinamespace
http://www.myserver/schemas/anotherxsinamespace.xsd">
<xy:myThirdElement>This is the info I need to get
at</xy:myThirdElement>
</xy:mySecondElement>
</myRootElement>
I've tried the following code (and variations) but cannot get it to work.
SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser",
true);
builder.setFeature ("http://xml.org/sax/features/validation", true);
builder.setFeature ("http://apache.org/xml/features/validation/schema",
true);
builder.setFeature("http://xml.org/sax/features/namespaces", true);
Document responseDoc = builder.build(new StringReader(rmresponse));
Element resroot = responseDoc.getRootElement();
Element second = resroot.getChild("mySecondElement");
Namespace xy = second.getNamespace();
Element third = second.getChild("myThirdElement");
String z = third.getText();
System.out.println("Content string: "+z);
I always end up with a NulPointerException
Can anyone advise me where I'm going wrong or how I get hold of the element
?
Cheers,
Steve
More information about the jdom-interest
mailing list