-1

i have a xmldocument with huge collection of nodes. xmldocument is loaded from string variable. i'm trying to get a nodes collection using xpath. my problem is when i run the app without debug the collection has few nodes( around 5 or 6) but if i debug and press F11 at the getting nodes collection line, i get different number of nodes based on the time i pause at the point. i have no clue on what's going on. is it because of the memory handling? or am i doing something wrong. (note: i'm removing the nodes from the DOM which are in the collection inside the foreach loop)

any idea?

if i pause at return, the collection has only 6 nodes.

if i pause at foreach, the collection has 556 nodes

Rifky
  • 1,444
  • 11
  • 26

1 Answers1

0

The XmlNodeList implementation might be built up lazily. And manipulating the document while iterating over the collection can change the collection. So usually, if you want to remove nodes found in an DOM XmlNodeList, you do it backwards e.g. for (int i = lstDel.Count - 1; i >= 0; i--) { lstDel[i].ParentNode.RemoveChild(lstDel[i]); }.

If you still have problems the please consider to post code samples allowing us to reproduce the problem, with screenshots alone it is difficult to tell what goes on.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110