Extract Node Values using XPATH
This may be a repeat question.
No offence meant
I am using XPATH to extract values from the nodes.
I need to extract the value of i:RequestedBy Node using XPATH
<?xml version="1.0" encoding="UTF-8"?>
<i:Interest>
<i:Status>0</i:Status>
<i:Generation>2</i:Generation>
<i:Details xsi:type="i:vanilla.details.stock">
<i:RequestedBy>AA.MM</i:RequestedBy>
The above XML is of type Document
-
Document msgDoc;
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr;
Object result=null;
try{
expr = xpath.compile("i:Interest/i:Details/i:RequestedBy/text()");
result = expr.evaluate(msgDoc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++){
System.out.println(nodes.item(i).getNodeValue());
}
}catch (XPathExpressionException e1){
e1.printStackTrace();
}
I am getting null/
Is my XPATH correct?

