Hello,

I want to remove all the nodes called "address" in a DOM object (org.w3c.dom.Document), and I have this piece of code trying to do so:

Document dom = null;
NodeList n_list = dom.getElementsByTagName("address");
Node parentNode = null;
Node removedNode = null;
for(int i = 0; i < n_list.getLength(); i++){
   parentNode = n_list.item(i).getParentNode();
   removedNode = parentNode.removeChild(n_list.item(i));
}
dom.getDocumentElement().normalize();


When I apply that code to the next XML file:

<?xml version="1.0" encoding="UTF-8"?><phonebook type="personal">
  <entry>
    <lastname>McLaughlin</lastname>
    <firstname>Brett</firstname>
    <address type="home">
      <street>1818 Writer's Lane</street>
      <city>Lorena</city>
      <state>TX</state>
      <zip>76655</zip>
    </address>
    <address type="work">
      <street>4810 Apartment Row</street>
      <city>Dallas</city>
      <state>TX</state>
      <zip>75219</zip>
    </address>
  </entry>

  <entry>
    <lastname>Greathouse</lastname>
    <firstname>Gary</firstname>
    <address type="home">
      <street>10012 Town East Drive</street>
      <city>Waco</city>
      <state>TX</state>
      <zip>76712</zip>
    </address>
  </entry>
</phonebook>

what I get is this other one:

<?xml version="1.0" encoding="UTF-8"?><phonebook type="personal">
  <entry>
    <lastname>McLaughlin</lastname>
    <firstname>Brett</firstname>

    <address type="work">
      <street>4810 Apartment Row</street>
      <city>Dallas</city>
      <state>TX</state>
      <zip>75219</zip>
    </address>
  </entry>

  <entry>
    <lastname>Greathouse</lastname>
    <firstname>Gary</firstname>

  </entry>
</phonebook>

There is still one "address node" in the file, the second one in the first "entry node". Any idea about why this is happening?

Thanks in advance.