[jdom-interest] XPath / default namespace
Rob Henley
RHENLEY at uk.ibm.com
Mon Sep 1 01:26:35 PDT 2003
With beta9 I'm trying to use XPath against a document with a default
namespace such as:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="name1" xmlns="http://my/standard/">
<AAA>aaa1</AAA>
<AAA>aaa2</AAA>
</definitions>
Without the default namespace in the document, this works fine:
XPath xpath = XPath.newInstance("//AAA");
List results = xpath.selectNodes(myDocument);
With the namespace in the document, the above code returns an empty list.
If I try:
XPath xpath = XPath.newInstance("//*");
List results = xpath.selectNodes(myDocument);
... I get the three elements. AAA for instance is returned with namespace
"http://my/standard/" and qualified name AAA.
I tried various ways of prefixing the element with the namespace without
luck. I also tried:
XPath xpath = XPath.newInstance("//AAA");
xpath.addNamespace("","http://my/standard/");
and ...
XPath xpath = XPath.newInstance("//N:AAA N http://my/standard/");
(The latter was based on an MSDN article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexxml/html/xml05202002.asp).
Both return an empty list.
Can anyone point me in the right direction?
Cheers
Rob
Rob Henley
rhenley at uk.ibm.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030901/f1fef8a5/attachment.htm
More information about the jdom-interest
mailing list