Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using XPATH in Java to extract attribute value.

807606May 4 2007 — edited May 5 2007
Hi,

I need to use XPATH to extract the value of attribute ID in element Instrmt

<?xml version="1.0" encoding="UTF-8"?>
<FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4">
	<Order Acct="MAC" Ccy="USD" ComplianceID="C" >
		<Hdr SeqNum="2" Snt="2007-04-23T08:22:53" />
		<Instrmt CpnRt="5.1" ID="US38259P" />
		<OrdQty Cash="1" Qty="500"/>
	</Order>
</FIXML>


Java Code :
===========

XPath xpath = XPathFactory.newInstance().newXPath();
expr = xpath.compile("//Order/Instrmt/@ID");
result = expr.evaluate(n, XPathConstants.NODESET);

NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
       System.out.println(nodes.item(i).getNodeValue()); 
}
I am not getting the value of ID: US38259P
Am I overlooking anything?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 2 2007
Added on May 4 2007
4 comments
3,533 views