public static String parserXml(String strXml) {
String json="";
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new InputSource(new StringReader(strXml)));
NodeList sessions = document.getChildNodes();
/*HashMap<String,String> hash=new HashMap<String,String>();*/
for (int i = 0; i < sessions.getLength(); i++) {
Node session = sessions.item(i);
NodeList sessionInfo = session.getChildNodes();
for (int j = 0; j < sessionInfo.getLength(); j++) {
Node node = sessionInfo.item(j);
NodeList sessionMeta = node.getChildNodes();
for (int k = 0; k < sessionMeta.getLength(); k++) {
System.out.println(sessionMeta.item(k).getTextContent());
json=sessionMeta.item(k).getTextContent();
// hash.put(sessionMeta.item(k).getNodeName(), sessionMeta.item(k).getTextContent());
}
}
}
// System.out.println("获取json"+json);
// try {
// JSONObject result=new JSONObject(json);
// //result.get("message");
// //result.get("statusCode");
// if(result.get("statusCode").equals("S")) {
// System.out.println(result.get("message"));
// }else {
// System.out.println("失败");
// }
// } catch (JSONException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
System.out.println("解析完毕");
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
} catch (ParserConfigurationException e) {
System.out.println(e.getMessage());
} catch (SAXException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
return json;
}
String json=SmpClient.parserXml(result);