public static String explainResult(String ncResultXML) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Map<String, String> resultMap = new HashMap<String, String>();
String unreadMail=null;
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
StringReader sr = new StringReader(ncResultXML);
InputSource is = new InputSource(sr);
Document doc = builder.parse(is);
NodeList nodeList = doc.getElementsByTagName("opensearch:totalResults");
//UnreadMail=nodeList.item(0).getTextContent();
//获取节点的值
unreadMail=nodeList.item(0).getFirstChild().getNodeValue();
}catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return unreadMail;
}
解析xml获取节点的值
最新推荐文章于 2021-06-22 08:46:31 发布