I have the following XML (which I receive and so do not have control of):
<root>
<elementA ....>
<elementB ....>
<nsx:elementC ...>
At a point in my code I have the Node - elementA
. What I am trying to do is get elementC
ignoring the namespaces (the document was parsed with namespace aware = true because I want to be able to use getLocalName
throughout my code.
I am using the following code:
Element elementA = ...;
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expression = xpath.compile(<see below for xpath);
Node result = expression.evaluate(elementA, XPathConstants.NODE);
Here are my results per tried XPath:
- "." --> elementA
- "./*" --> elementB
- "./elementB" --> null
- "elementB" --> null
I don't get why if "./*" gives me elementB
, "./elementB" gives me null.
Eventually, what I would like is something like: "./:elementB/:elementC"