It should be
cNode.getParentNode().removeChild(cNode);
or
nod.removeChild(cNode);
Lets say A
is the parent node of nod
. What you are currently trying to do is to delete the child cNode
from A
, whereas you want to remove the child cNode
from nod
Update
If you want to delete the whole <user/>
record than your code can be much simpler. No need for deleting each and everyone child element by hand.
XPath xPath = XPathFactory.newInstance().newXPath();
String expression = "//user[email='" + sEmail + "']";
System.out.println(expression);
Node node = (Node) xPath.compile(expression).evaluate(xmlDocument,XPathConstants.NODE);
if (node != null) node.getParentNode().removeChild(node);