版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yikong2yuxuan/article/details/70010120
/**
* 遍历解析xml
* @param infoXML
* @return
*/
public static Map<String, Object> doXml(String infoXML) {
Document document;
Map<String, Object> map = new HashMap<String, Object>();
try {
document = DocumentHelper.parseText(infoXML);
Element root = document.getRootElement();
Iterator it = root.elements().iterator();
while (it.hasNext()) {
Element info = (Element) it.next();
map.put(info.getName(), info.getText());
Iterator itc = info.elements().iterator();
while (itc.hasNext()) {
Element infoc = (Element) itc.next();
map.put(infoc.getName(), infoc.getText());
}
}
} catch (DocumentException e) {
e1.printStackTrace();
}
return map;
}
* 遍历解析xml
* @param infoXML
* @return
*/
public static Map<String, Object> doXml(String infoXML) {
Document document;
Map<String, Object> map = new HashMap<String, Object>();
try {
document = DocumentHelper.parseText(infoXML);
Element root = document.getRootElement();
Iterator it = root.elements().iterator();
while (it.hasNext()) {
Element info = (Element) it.next();
map.put(info.getName(), info.getText());
Iterator itc = info.elements().iterator();
while (itc.hasNext()) {
Element infoc = (Element) itc.next();
map.put(infoc.getName(), infoc.getText());
}
}
} catch (DocumentException e) {
e1.printStackTrace();
}
return map;
}