关于对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();
  }

 

 

posted @ 2013-03-27 10:34  无尘24  阅读(139)  评论(0编辑  收藏  举报