关于对XML的处理

前端之家收集整理的这篇文章主要介绍了关于对XML的处理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

目前看到的对XML的处理有2套,一套是使用jdom,另一套是使用dom4j

jdom示例:

SAXBuilder builder = new SAXBuilder(false);
InputStream xmlInput = new FileInputStream("xxx.xml");
Document doc = builder.build(xmlInput);
Element root = doc.getRootElement();


Element addDTSVersion = new Element("VersionA");
addDTSVersion.setText(configDTSVersion);     
Element addrallyVersion = new Element("VersionB");         
addrallyVersion.setText(configRallyVersion);

Element addTime = new Element("Maping");         
addTime.addContent(addDTSVersion);         
addTime.addContent(addrallyVersion);

root.addContent(addTime);

List<Element> Mapinglist = root.getChildren("Maping");

XMLOutputter outputter = new XMLOutputter();try {String locaFileName = ConfigUtils.class.getResource("/"+fileName).toString();locaFileName = locaFileName.substring(6);outputter.output(doc,new FileOutputStream(locaFileName));} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}

猜你在找的XML相关文章