• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Deleting the children from node - xml

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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,


 
Sheriff
Posts: 28326
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic