This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Deleting the children from node - xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Deleting the children from node - xml " Watch "Deleting the children from node - xml " New topic

Deleting the children from node - xml

Sathish Kumar Subramanian

Joined: Nov 22, 2010
Posts: 8

I want to remove total list of children from the node selected.

Here is the xml which I use,

When selecting the diagram id 'abc', all the children inside the <Diagram> </Diagram> tag must be deleted, and also the Diagram tag.

Here the code i used,

Sathish Kumar Subramanian
Java Newbie
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

You have this list: (0=child1, 1=child2, 2=child3). The first time through the loop you delete entry number 0, so now you have (0=child2, 1=child3). Then you delete entry number 1, so now you have (0=child2). Finally you delete entry number 2, which doesn't exist, so you still have (0=child2).

Either you should delete the entries in reverse order (2, then 1, then 0) or you should delete entry number 0 every time through the loop.

This is a classic gotcha of programming languages, nothing to do with XML at all, and people have been getting tricked by it for over 40 years now. You aren't the first.
I agree. Here's the link:
subject: Deleting the children from node - xml
Similar Threads
how to generate a xml file on submit action with all the form data
how to write the data from text fields of my swing application to an xml file dynamically?
reading web.xml by XPATH
parsing doubt
Java code to append data into a existing xml file