[jdom-interest] XPath and Namespaces

Carsten Karkola carsten.karkola at mailbox.tu-dresden.de
Fri Jul 26 06:12:12 PDT 2002


Date sent:      	Fri, 26 Jul 2002 14:58:53 +0200
From:           	Laurent Bihanic <laurent.bihanic at atosorigin.com>
To:             	Carsten Karkola <carsten.karkola at mailbox.tu-dresden.de>
Subject:        	Re: [jdom-interest] XPath and Namespaces

> 
> Use a prefix:
> 
> org.jaxen.XPath path = new JDOMXPath("//foo:b");
> path.addNamespace("foo", doc.getRootElement().getNamespace().getURI());
> List results = path.selectNodes(doc);
> 
> Laurent
Thank you a lot, it sounds that easy, but I'd never guessed, to put in any string there - now it works!
Regards, Carsten
> 
> Carsten Karkola wrote:
> > Thank you for your quick response, but how do I get the b nodes in the 
> > following document:
> > 
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <test
> >   xmlns="http://www.tu-dresden.de/bau/test"
> >   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >   xsi:schemaLocation="http://www.tu-dresden.de/bau/test test.xsd">
> >   <a>
> >     <b>test1</b>
> >   </a>
> >   <a>
> >     <b>test2</b>
> >   </a>
> >   <a>
> >     <b>test3</b>
> >   </a>
> > </test>
> > 
> > What should I use instead of
> >  org.jaxen.XPath path = new JDOMXPath("//b");
> >  path.addNamespace("",doc.getRootElement().getNamespace().getURI());
> >  List results = path.selectNodes(doc);
> > 
> > to get all the <b> elements. How should I add the namespace, because 
> > without the path.addNamespace I get also no results.
> > 
> > Regards, Carsten
> 





More information about the jdom-interest mailing list