xml:
2
识别成功
张三
男
满
1984-03-28
java代码:
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(resultXML)));
NodeList status = doc.getElementsByTagName("status");//取标签
String statusCode = status.item(0).getFirstChild().getNodeValue();//取值
NodeList books = doc.getElementsByTagName("item");
Node type = doc.getElementsByTagName("card").item(0)
if (books != null) {
for (int i = 0; i < books.getLength(); i++) {
Node book = books.item(i);
String str = book.getAttributes().getNamedItem("desc").getTextContent();//取参数
map.put(str, book.getFirstChild().getNodeValue());
}
}
} catch (Exception e) {
e.printStackTrace();
}