public boolean writeXmlFromDB(People p) {
boolean success = false;
SAXBuilder builder = new SAXBuilder();
try {
Document doc = builder.build(new File("WebRoot/WEB-INF/people.xml"));
Element root = doc.getRootElement();
List l = root.getChildren();
Element ee = (Element)l.get(0);
ee.setAttribute("exists", "y");
Iterator it = l.iterator();
while (it.hasNext()) {
Element e = (Element)it.next();
}
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return success;
}
以上是我的方法,我就是想把xml文档里的一个叫person的节点里的一个叫做exists的属性的值给修改了,以上的代码没有提示错误但是,却没有任何效果啊,请高手指教12.谢谢了
------解决方案--------------------
好象你修改后没保存吧
XMLOutputter out=new XMLOutputter();
out.output(doc, new FileWriter("test.xml"));