I have the below xml string
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Structure>
<LongUnsigned value="142794"/>
<OctetString value="07E2051E030F1E0404800000"/>
<Structure>
<OctetString value="07E2051E030F1E0404800000"/>
<OctetString value="66574536387"/>
<Array>
<Structure><OctetString value="0000000000000001"/><OctetString value="9889892347"/></Structure>
<Structure><OctetString value="00098347586768574"/><OctetString value="6283046502"/></Structure>
<Structure><OctetString value="0000011000000001"/><OctetString value="899734729847586"/></Structure>
</Array>
</Structure>
</Structure>
I am using the below xpath but it always returns an empty string.
XPath xPath = XPathFactory.newInstance().newXPath();
try {
String eval = xPath.evaluate("//Structure/Structure/Array", new InputSource(new StringReader(xmlString)));
System.out.println("Eval:" + eval);
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I tried running this xpath online and it seems to work just fine. What am i missing in Java that makes it not work as expected.
Documentnode? Are you sure it is correct to use anInputSourceas the context?DocumentandInputSourceas a string. The string was actually generated from aDocumentinstance.