jdom解析XML文件
程序员文章站
2022-05-28 11:42:29
...
Reader reader = new StringReader(XXX.xml);
InputSource is = new InputSource(reader);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
SAXBuilder build = new SAXBuilder();
Document doc = build.build(is);
Element root=doc.getRootElement();
java.util.List<Element> list = root.getChildren("attribute");
Element rootelem=null;
for (Element elem :list) {
String name = elem.getAttributeValue("displayname");
String value = elem.getValue();
String before = elem.getChildText("before");
oldvalue.put(name, before);
if (before !=null) {
String str = value.replace(before, "");
newvalue.put(name, str);
} else {
newvalue.put(name, value);
}
}
上一篇: jQuery 与 js之入口函数
下一篇: Python笔记