I have to extract attr
value from such XML:
<FIXML xmlns="http://www.fixprotocol.org/FIXML-5-0-SP2">
<TAG attr="value">
...
</TAG>
</FIXML>
and try to use such Java code
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/FIXML/TAG/@attr");
XmlPayloadConverter converter = new DefaultXmlPayloadConverter();
Node node = converter.convertToNode(xmlStr);
Object result = expression.evaluateAsString(node);
Unfortunately, the result
value is always empty here. If I remove namespace attr xmlns="http://www.fixprotocol.org/FIXML-5-0-SP2"
the code works as expected (result
has value
string).
How to ignore the namespace in my Java code example?
UPDATE: looks like I have to use XPath local-name()
function in my expression but how to use it practically in my case?
SOLUTION: in my case the correct XPath exprtssion is "/*[local-name()='FIXML']/*[local-name()='TAG']/@attr"