Hi -
I'm having problems getting my head round the use of XPath in Axiom,
especially when using namespaces.
With an XML snippet like this:
<?xml version="1.0" encoding="utf-16"?>
<X>
<Y>
<Z>test</Z>
</Y>
</X>
And a code snippet like this:
String xpathString = "/X/Y/Z";
AXIOMXPath xpathExpression = new AXIOMXPath(xpathString);
OMElement element = (OMElement)xpathExpression.selectSingleNode(root);
I can retrieve the element from the XML without any problem.
However, with XML like this:
<?xml version="1.0" encoding="utf-16"?>
<X xmlns:xsi="A " xmlns:xsd="B" xmlns="C">
<Y>
<Z>test</Z>
</Y>
</X>
OMNamespace namespace = documentElement.getNamespace();
String prefix = namespace.getPrefix();
String uri = namespace.getNamespaceURI();
AXIOMXPath xpathExpression = new AXIOMXPath(xpathString);
xpathExpression.addNamespace(prefix, uri);
OMElement element = (OMElement)xpathExpression.selectSingleNode(root);
I get no results.
Can anyone spot why this might be?
Any advice would be much appreciated.
Robert