Using XPATH to extract value.

I need some help to extract the LatestFillQuantity element value using XPATH.

in Java.

I am unable to extract the value of 10000.

Please help as to what have I done wrong.?

The Document configNode contains the flwg:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>

<i:Interest >

<i:Generation>3</i:Generation>

<i:Extension>

<i:Active.From/>

<i:Order>

<i:Status>Confirm</i:Status>

<i:LatestFillQuantity>100</i:LatestFillQuantity>

</i:Order>

</i:Extension>

</i:Interest>

My Java Code

privatevoid extractValue(Document configNode)

{

XPathFactory factory = XPathFactory.newInstance();

XPath xpath = factory.newXPath();

try{

XPathExpression expr

= xpath.compile("//i:Order/i:LatestFillQuantity/text()");

Object result = expr.evaluate(configNode, XPathConstants.NODESET);

NodeList nodes = (NodeList) result;

for (int i = 0; i < nodes.getLength(); i++){

System.out.println(nodes.item(i).getNodeValue());

}

}catch(Exception e){

System.out.println("Sorry,this aint working");

}

}

[1813 byte] By [bhuru_luthriaa] at [2007-11-27 6:42:42]
# 1

The nodes being parsed are namespace prefixed.

To parse a namespace node with the JDK 5.0 javax.xml.xpath package, set the NamespaceContext on the XPath object.

An implementation of NamespaceContext with a single prefix corresponding to a namespace uri:

public class NamespaceContextImpl implements NamespaceContext{

public String uri;

public String prefix;

public NamespaceContextImpl(){}

public NamespaceContextImpl(String prefix, String uri){

this.uri=uri;

this.prefix=prefix;

}

public String getNamespaceURI(String prefix){

return uri;

}

public void setNamespaceURI(String uri){

this.uri=uri;

}

public String getPrefix(String uri){

return prefix;

}

public void setPrefix(String prefix){

this.prefix=prefix;

}

public Iterator getPrefixes(String uri){return null;}

}

dvohra09a at 2007-7-12 18:12:55 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...