I’ve not done much with linq to xml, but all the examples I’ve seen load the entire XML document into memory.
What if the XML file is, say, 8GB, and you really don’t have the option?
My first thought is to use the XElement.Load Method (TextReader) in combination with an instance of the FileStream Class.
QUESTION: will this work, and is this the right way to approach the problem of searching a very large XML file?
Note: high performance isn’t required.. i’m trying to get linq to xml to basically do the work of the program i could write that loops through every line of my big file and gathers up, but since linq is “loop centric” I’d expect this to be possible….
Using
XElement.Loadwill load the whole file into the memory. Instead, useXmlReaderwith theXNode.ReadFromfunction, where you can selectively load notes found byXmlReaderwithXElementfor further processing, if you need to. MSDN has a very good example doing just that: http://msdn.microsoft.com/en-us/library/system.xml.linq.xnode.readfrom.aspxIf you just need to search the xml document,
XmlReaderalone will suffice and will not load the whole document into the memory.