SAXReader reader = new SAXReader();
Document document;
String path=ServletActionContext.getRequest().getRealPath("/xml");
document = reader.read(path+"/admin/名称.xml");
// 获得根节点以及属性
Element root = document.getRootElement();
// 获得根节点的名字,属性,属性值
for (Iterator iterator = root.attributeIterator(); iterator.hasNext();) {
Attribute attri = (Attribute) iterator.next();
}
if(root.elementIterator().hasNext()==false){//返回为false的话,就向xml文件中添加子节点
business.setBeforeIP("-connect ");
//创建businesses节点,business,update
Element businesses=root.addElement("businesses");
Element business= businesses.addElement("business");
Element update= business.addElement("update");
//设置business中的属性及属性值
business.addAttribute("name","
利用dom4j学习xml(二) 添加子节点并查看子节点的属性值
最新推荐文章于 2022-08-06 11:51:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)