i have one problem to delete the node in xml ,i have node list i stored some details,now i searched by one node value (somevalue),and i want to delete the corresponding child nodes here is 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");
}
}
so now i want to delete that node which has that value "172.1.2.111";what is wrong with this code