对于下面的消息,我的解析代码是给:name #text value
.
为什么要恢复这个记录?
信息:
<emp>
<emp_name>david</emp-name>
<emp-no>123</emp-no>
</emp>
代码:
final Document doc = parser.loadXml(message);
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getDocumentElement().getChildNodes();
public Map<String, String> getElementKeyValue(NodeList nodeList) {
Map<String, String> elements = new HashMap<String, String>();
if (nodeList != null && nodeList.getLength() > 0) {
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i); // Take the node from the list
NodeList valueNode = node.getChildNodes(); // get the children // of the node
String value = (valueNode.item(0) != null) ? valueNode.item(0)
.getNodeValue() : "";
System.out.println("name " + node.getNodeName() + " value "
+ value);
elements.put(node.getNodeName(), value);
}
}
return elements;
}