0

I want to write a method to remove given index from the nodelist. is there any way to do it?

If i try this below code it removes the xml, but still the empty node exists, the count of the xmlnodelist is same as before remove.

public static void removeItem(XmlNodeList nodes, int index)
{
   nodes.Item(i).RemoveAll();
}

Can anyone help me how to remove the particular item by index?

Mathiyazhagan
  • 1,389
  • 3
  • 13
  • 37
  • Possible duplicate of [How to remove an XmlNode from XmlNodeList](https://stackoverflow.com/questions/875136/how-to-remove-an-xmlnode-from-xmlnodelist) – Shakir Ahamed Nov 15 '18 at 05:25

1 Answers1

0

I'm little confused about the variable i in your code. Anyway, if you have to remove a node from the XmlNodeList, you have to remove the node from its parentNode. so the method can be rewritten as like the following:

public static void removeItem(XmlNodeList nodes, int index)
{
   nodes[index].ParentNode.RemoveChild(nodes[index])
}
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
  • Actually i tried this solution , but it throws below exception , thats why i want to try some other option where ProcessNode is called exactly 1025 times. You can find the limit specified on line 392 and the operation on line 396 of the code specified here: https://referencesource.microsoft.com/#system.xml/System/Xml/XPath/Internal/QueryBuilder.cs – Mathiyazhagan Nov 15 '18 at 06:47