我有一个XML
文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<coffeeOrder>
<addition>null</addition>
<cost>3.0</cost>
<id>1</id>
<links>http://localhost:9080/cs9322.ass2/rest/payment/1</links>
<status>cancelled</status>
<type>espresso</type>
</coffeeOrder>
我正在尝试检索value
的{{1}}。
目前我有以下内容:
status
然而,我发现我经常得到try {
Document document = loadXMLFromString(orderXML);
NodeList nodeList = document.getDocumentElement().getChildNodes();
// Cycle through nodes, until "status" or "paymentType" element found
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element elem = (Element) node;
System.out.println(orderXML);
System.out.println(elem.toString());
if (type.equals("order") && elem.getNodeName().equals("status")){
status = elem.getNodeValue();
} else if(type.equals("payment") && elem.getNodeName().equals("paymentType")){
status = elem.getNodeValue();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
。
null
返回
System.out.println(elem.toString());
即使
[status: null]
表明System.out.println(orderXML);
不是status
有人知道我在这里做错了吗?