0

I'm trying to remove the xml nodes from the XML file without using XmlDocument or XDocument. I got many examples from net which all discuss about either XmlDocument or XDocument(Linq2XML). i can not use either of the options(XmlDocument or Linq2XML Xdocument) because of the following 2 reasons:

1.they load the whole Xml file into memory and perform the opertaions (like remove node,add node etc.,) in my case Xml files are very huge.
2.both XmlDocument and XDocument crash if there is an invalid character in xml file.

Please suggest me some good alternative of removing the nodes without using XmlDocument or XDocument.

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
  • 1
    You should look at Regular Expressions ([Regex Class](http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx), [Regular Expression Language Ref](http://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx)) they are very good at processing large strings. – Jeffrey Wieder Sep 18 '14 at 13:10
  • for that i need to first load the whole document into memory which is very expensive again :( – Sudhakar Tillapudi Sep 18 '14 at 13:24
  • `XmlReader` + `XmlWriter` maybe : [XmlReader - I need to edit an element and produce a new one](http://stackoverflow.com/questions/1502450/xmlreader-i-need-to-edit-an-element-and-produce-a-new-one) – har07 Sep 18 '14 at 13:30
  • Could you provide an example of what kind of edit you need to do? Is it possible to "stream" the file? I've used html agility pack with great success before when encountering bad formatting and chars, (though it still loads into memory) http://htmlagilitypack.codeplex.com/ – flindeberg Sep 18 '14 at 13:43
  • i need to remove specific node from the xml file. – Sudhakar Tillapudi Sep 18 '14 at 13:44
  • Does the node have sub-nodes? Should they be removed as well? – flindeberg Sep 18 '14 at 13:46
  • @flindeberg: yes it has subnodes and i have to remove complete node – Sudhakar Tillapudi Sep 18 '14 at 13:58
  • 1
    why not use a stream to read in the lines checking for the node you wish to remove. Once you find the node you just need to then find the closing element tag and you should then have the start and end position of what needs to be removed. – Sorceri Sep 18 '14 at 15:26

0 Answers0