日期:2014-05-20 浏览次数:20693 次
<ORDER_BOOK>
<LINEITEM DATA=\"ORDER_RECORD\" ORDER_NO=\"4172\" QUANTITY=\"2000\" EXECUTED_QUANTITY=\"2000\">
<LINEITEM DATA=\"EXECUTION\" EXECUTED_QUANTITY=\"2000\" />
</LINEITEM>
<LINEITEM DATA=\"ORDER_RECORD\" ORDER_NO=\"4173\" QUANTITY=\"3000\" EXECUTED_QUANTITY=\"1000\">
<LINEITEM DATA=\"EXECUTION\" EXECUTED_QUANTITY=\"1000\" />
</LINEITEM>
<LINEITEM DATA=\"ORDER_RECORD\" ORDER_NO=\"4172\" QUANTITY=\"2000\" EXECUTED_QUANTITY=\"0\"/>
</ORDER_BOOK>
String xml="<ORDER_BOOK>" +
"<LINEITEM DATA=\"ORDER_RECORD\" ORDER_NO=\"4172\" QUANTITY=\"2000\" EXECUTED_QUANTITY=\"2000\">" +
"<LINEITEM DATA=\"EXECUTION\" EXECUTED_QUANTITY=\"2000\" />" +
"</LINEITEM>" +
"<LINEITEM DATA=\"ORDER_RECORD\" ORDER_NO=\"4173\" QUANTITY=\"3000\" EXECUTED_QUANTITY=\"1000\">" +
"<LINEITEM DATA=\"EXECUTION\" EXECUTED_QUANTITY=\"1000\" />" +
"</LINEITEM>" +
"<LINEITEM DATA=\"ORDER_RECORD\" ORDER_NO=\"4172\" QUANTITY=\"2000\" EXECUTED_QUANTITY=\"0\"/>" +
"</ORDER_BOOK> ";
SAXReader reader=new SAXReader();
Document doc=reader.read(new StringReader(xml));
List<Node> list=doc.selectNodes("//ORDER_BOOK/LINEITEM[@DATA='ORDER_RECORD']");
for(Node node:list){
System.out.println("QUANTITY="+node.selectSingleNode("./@QUANTITY").getText());
System.out.println("EXECUTED_QUANTITY="+node.selectSingleNode("./@EXECUTED_QUANTITY").getText());
}