[java]代码库
package com.gsww.eosp.service.gateway.impl;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.xml.sax.InputSource;
public class aa {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
System.out.println("--------------------");
String custCode = null;
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Package><StreamingNo>XJ20120929152306700</StreamingNo><OPFlag>0104</OPFlag><ProductID>JXHDWWJ</ProductID><BizID>18997773429</BizID><AreaCode>909</AreaCode><CustID>90918997773429</CustID><CustAccount>18997773429</CustAccount><CustName>刘艳杰</CustName><ProductInfo><Product><ProductInstID>8</ProductInstID><ProductType>20000008</ProductType><ProductValue>909013</ProductValue><ParentType></ParentType><ProductParentInstID></ProductParentInstID></Product><Product><ProductInstID>24</ProductInstID><ProductType>10001931</ProductType><ProductValue>10</ProductValue><ParentType></ParentType><ProductParentInstID></ProductParentInstID></Product><Product><ProductInstID>33</ProductInstID><ProductType>70002</ProductType><ProductValue>30</ProductValue><ParentType></ParentType><ProductParentInstID></ProductParentInstID></Product><Product><ProductInstID>45</ProductInstID><ProductType>10000579</ProductType><ProductValue>09-29-2012</ProductValue><ParentType></ParentType><ProductParentInstID></ProductParentInstID></Product><Product><ProductInstID>65</ProductInstID><ProductType>10000590</ProductType><ProductValue>09-29-2022</ProductValue><ParentType></ParentType><ProductParentInstID></ProductParentInstID></Product></ProductInfo><Summary></Summary><ReturnStatus>00000</ReturnStatus></Package>";
System.out.println("xml:"+xml);
SAXBuilder sax = new SAXBuilder();
Document doc;
try {
doc = sax.build(new InputSource(new StringReader(xml)));
Element root = doc.getRootElement();
root = doc.getRootElement(); // 得到查询信息的根节点
String StreamingNo = root.getChildText("StreamingNo");
System.out.println(StreamingNo);
System.out.println("************************");
Element productElement = root.getChild("ProductInfo");
List<Element> productInfoElement = new ArrayList<Element>();
if (productElement != null) {
productInfoElement = productElement.getChildren("Product");
}
Map<String, String> productAttrMap = new HashMap<String, String>();
for (Element ele : productInfoElement) {
productAttrMap.put(ele.getChildText("ProductType"), ele.getChildText("ProductValue"));
System.out.println("ProductType:"+ele.getChildText("ProductType"));
System.out.println("ProductValue:"+ele.getChildText("ProductValue"));
}
if (productAttrMap != null) {
custCode = productAttrMap.get("20000008");
}
System.out.println("custCode="+custCode);
} catch (Exception e) {
}
}
}