JAVA解析XML字符串(转化成Map类型)
作者:
chuan_bai | 来源:发表于
2017-09-27 11:30 被阅读29次public static Map<String, String> readStringXml(String xml) throws DocumentException {
Document doc = DocumentHelper.parseText(xml);
Element books = doc.getRootElement();
System.out.println("rootNode:" + books.getName());
Iterator Elements = books.elementIterator();
Map<String, String> map = new HashMap<>();
while (Elements.hasNext()) {
Element user = (Element) Elements.next();
System.out.println("node=" + user.getName() + "\ttext=" + user.getText());
map.put(user.getName(), user.getText());
}
return map;
}
本文标题:JAVA解析XML字符串(转化成Map类型)
本文链接:https://www.haomeiwen.com/subject/qbzyextx.html
网友评论