0

Below is my code to load xml into xml document.

                filestream = File.OpenRead("Application Data\MSP\XMLDATA.XML")
                myXmlDoc = New XmlDocument
                myXmlDoc.Load(filestream)

But it throws out of memory exception. Is there is any way to load xml into xmldocument partially? or How can I solve this.

Siva
  • 1,849
  • 2
  • 13
  • 28
  • try `myXmlDoc.LoadXML "Application Data\MSP\XMLDATA.XML"` – Florent B. Oct 06 '17 at 13:23
  • Tried that already.. Throwing that same issue – Siva Oct 06 '17 at 13:24
  • What size is the file "Application Data\MSP\XMLDATA.XML"? Incidentally, it would be best to use a full path to the file so that you can be sure that it is using the file that you think it is using. What sort of information do you want from the file? – Andrew Morton Oct 06 '17 at 13:28
  • Possible duplicate of [How to parse very huge XML Files in C#?](https://stackoverflow.com/questions/15772031/how-to-parse-very-huge-xml-files-in-c) – Andrew Morton Oct 06 '17 at 13:29
  • Size of the XML file 4.51 MB. Am doing this for the Old device.. I need to read the XML file and Convert it into txt file by the tag name. – Siva Oct 06 '17 at 13:44
  • On exactly which line does it give the error? – Andrew Morton Oct 06 '17 at 14:12
  • on myXmlDoc.Load( "Application Data\MSP\XMLDATA.XML").. I also tried myXmlDoc.LoadXML ("Application Data\MSP\XMLDATA.XML") – Siva Oct 06 '17 at 14:16

1 Answers1

0

Are you sure that the out of memory exception is because the document is large? This exception could be due to an error in the syntax of the document.

I mean that the error could be due to some problem reading the file rather than the size of the file itself. If the XML is poorly formed, maybe something is causing an infinite loop of lookups or something. 4.5 Meg isn't that big

Try to read the document with XmlReader.

codeDom
  • 1,623
  • 18
  • 54
  • Yes am Sure.. Its out of memory exception – Siva Oct 06 '17 at 13:24
  • @codeDom Your reply should be a comment, not an answer, as it is asking for clarification. – Andrew Morton Oct 06 '17 at 14:33
  • 1
    @Siva, I think what codeDom meant is that the error could be due to some problem reading the file rather than the size of the file itself. If the XML is poorly formed, maybe something is causing an infinite loop of lookups or something. 4.5 Meg isn't that big. – dwilliss Oct 06 '17 at 18:39
  • 1
    @dwilliss Thanks for explaining what I mean – codeDom Oct 07 '17 at 16:07
  • Gentleman If I load 2 Mb file its loading.. Am doing this for a older device. – Siva Oct 09 '17 at 03:57