[jdom-interest] Building with Namespaces

Laurent Bihanic laurent.bihanic at atosorigin.com
Fri Jun 27 07:29:24 PDT 2003


You should try with:
    Element third = second.getChild("myThirdElement", xy);

Laurent


Steve Beech wrote:

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

-- 
                  wWw
                 (o o)
-------------ooO-(_)-Ooo-----------------------------------------------
Laurent Bihanic                | Tel: +33 (0)1 55.91.21.93 (direct)
AtosOrigin Systems Integration |      +33 (0)1 55.91.20.00
e-Business / SC                | Fax: +33 (0)1 55.91.22.31
Les Miroirs - Bat. C           |
18, avenue d'Alsace            |
F-92926 La Defense Cedex       | E-mail: laurent.bihanic at atosorigin.com
-----------------------------------------------------------------------

"Microsoft isn't the answer. Microsoft is the question and the answer
  is no."


DISCLAIMER:
The opinions expressed are entirely my own and may not necessarily be
those of my employer.  Also, I am not now nor have I ever been a
lawyer.  My opinions are provided as-is with absolutely no warrantee of
merchantability or fitness for any particular use.  Besides, you can't
prove I typed this.  No body saw me type this.  Who says I typed this?




More information about the jdom-interest mailing list