[jdom-interest] JDOM, XPath and Namespaces
Jon Sharp
jon.sharp at j2ssolutions.com
Mon Aug 18 02:10:21 PDT 2003
>
>Jon Sharp wrote:
>>I tried XPath.addNamespace() but without any joy, eg following retuns 0
>>items in List:
>>Namespace ns=Namespace.getNamespace("http://www.xxxx.com/envelope");
>>XPath xp = XPath.newInstance("/TopLevElement");
>>xp.addNamespace(ns);
>>List xlist = xp.selectNodes(tdoc);
>
>The key point to remember is that there is no default namespace in XPath.
>That is, whether your document uses namespace prefixes or not, you have to
>use prefixes when referencing namespaces in XPath expressions. These
>prefixes do not have to match the ones used in the document if you declare
>the namespace using XPath.addNamespace().
>
>For example:
> Namespace ns=Namespace.getNamespace("foo",
> "http://www.xxxx.com/envelope");
> XPath xp = XPath.newInstance("/foo:TopLevElement");
> xp.addNamespace(ns);
> List xlist = xp.selectNodes(tdoc);
>
>Laurent
Many thanks, this sorted it out!
Jon
----------
Jon Sharp tel: +44 1273 504004 mobile: +44 7739 430793
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030818/242e3b05/attachment.htm
More information about the jdom-interest
mailing list