public static void removeXML() {
SAXBuilder sb = new SAXBuilder();
Document doc = null;
try {
doc = sb.build("person.xml");
Element root = doc.getRootElement();
List<Element> list = root.getChildren("person");
for (Element el : list) {
if ("ID001".equals(el.getAttributeValue("id"))) {
root.removeContent(el);
}
}
} catch (Exception e) {
e.printStackTrace();
}
saveXML(doc); //删除操作后,不要忘记再次进行存储。才能更新xml文件
}
public static void main(String[] args) {
// createXML(); //创建XML
// readXML(); //获取XML
// updateXML(); //修改XML
removeXML(); //删除XML
}
【Java开发】--jdom解析xml-删除xml
最新推荐文章于 2022-08-07 00:09:35 发布