我正在尝试解析以下字符串以获得“ orderNo”
String requestBody="<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ShipmentList><Shipment ActualShipmentDate="2018-06-26T11:25:00+05:30" DocumentType="0005" TotalWeight="55.5" TotalWeightUOM="LB" TrackingNo="9461236897846412938163"><ShipmentLines><ShipmentLine OrderNo="1529904772887" PrimeLineNo="1" Quantity="3" SubLineNo="1"/><ShipmentLine OrderNo="1529904772887" PrimeLineNo="2" Quantity="3" SubLineNo="1"/><ShipmentLine OrderNo="1529904772887" PrimeLineNo="3" Quantity="3" SubLineNo="1"/><ShipmentLine OrderNo="1529904772887" PrimeLineNo="4" Quantity="3" SubLineNo="1"/><ShipmentLine OrderNo="1529904772887" PrimeLineNo="5" Quantity="3" SubLineNo="1"/></ShipmentLines><Extn ExtnPackageASN="55538770655551006451" ExtnPackageID="6247442951596360944" ExtnPackLength="25.0" ExtnLengthUOM="IN" ExtnPackWidth="20.0" ExtnWidthUOM="IN" ExtnPackHeight="16.0" ExtnHeightUOM="IN" ExtnCarrierMethodId="83"/></Shipment></ShipmentList>";
NodeList nl = null;
try {
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(requestBody);
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("//ShipmentList/Shipment/ShipmentLines/ShipmentLine[@OrderNo]");
nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
} catch (XPathExpressionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ParserConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SAXException e1) {
我已经尝试使用上面的代码片段,但是有人可以让我知道这是什么错误,这并没有帮助
九州编程
相关分类