我有一个问题要删除 xml 中的节点,我有节点列表我存储了一些详细信息,现在我按一个节点值(某个值)搜索,我想删除相应的子节点,这里是 xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Serverinformation>
<server>
<serverip>172.1.2.111</serverip>
<port>4000</port>
<dbip>162.2.1.111</dbip>
<dbname>sample</dbname>
<nor>1000</nor>
</server>
<server>
<serverip>182.1.2.111</serverip>
<port>6000</port>
<dbip>152.2.1.111</dbip>
<dbname>sample2</dbname>
<nor>1000</nor>
</server>
</Serverinformation>
//
Element e = doc.getDocumentElement();
NodeList nodeList = doc.getElementsByTagName("server");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
NodeList nodelist = element.getElementsByTagName("serverip");
Element element1 = (Element) nodelist.item(0);
NodeList fstNm = element1.getChildNodes();
String str=(fstNm.item(0).getNodeValue());
String t="172.1.2.111";
if(str.equals(t))
{
element1.getParentNode().removeChild(element1);//here is the problem
count=1;
break
}
continue;
}
}
if(count==1)
System.out.println("item found");
else
System.out.println("item not found");
}
}
所以现在我想删除那个值为“172.1.2.111”的节点;这段代码有什么问题