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?

[1523 byte] By [bhuru_luthriaa] at [2007-11-27 5:24:26]
# 1
I don't know if your XPath is correct or not. Your XML is not well-formed because the namespace declarations are missing. And I don't see where you set the namespace context for your XPath object; that is quite likely why it doesn't do what you want.
DrClapa at 2007-7-12 11:50:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...