目前看到的对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();}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。