Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

Re: [jdom-interest] xpath + namespace + no prefix

Laurent Bihanic

2006-11-15

Replies:


XPath xPath = XPath.newInstance("//foo:C");
xPath.addNamespace("foo", "http://www.somewhere.com");
List<Element> elements = xPath.selectNodes(document);

XPath does not support any default namespace. The namespace prefix in the
XPath expression does not have to match the one used in the document, only the
namespace URI is checked.

Laurent


David Harrigan a ?crit :
> Hi,
>
> I'm having a bit of a problem. I'm receiving an XML document with the
> following example stucture:
>
>
>  
>   <C>1234</C>
>  
>
>
> If I try this:
>
> XPath xPath = XPath.newInstance("//C");
> List<Element> elements = xPath.selectNodes(document);
>
> I get back no elements
>
> If I try this:
>
> XPath xPath = XPath.newInstance("//C");
> xPath.addNamespace("", "http://www.somewhere.com");
> List<Element> elements = xPath.selectNodes(document);
>
> I get back no elements
>
> I believe the inclusions of the namespace is throwing xPath off (because
> the element has no prefix?)
>
> Any help on this would be appreciated.
>
> Thanks
>
> -=david=-
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.