It looks like your file is too large for your environment. Downloading the DOM for a large file can be problematic, especially when using the win32 platform (you did not specify whether this is true).
You can combine the speed and efficiency of XmlReader memory with the convenience of XElement / Xnode, etc. and use XStreamingElement to save the converted content after processing. This is significantly more efficient for storing large files.
Here is an example in pseudo code:
// use a XStreamingElement for writing var st = new XStreamingElement("root"); using(var xr = new XmlTextReader(stream)) { while (xr.Read()) { // whatever you're interested in if (xr.NodeType == XmlNodeType.Element) { var node = XNode.ReadFrom(xr) as XElement; if (node != null) { ProcessNode(node); st.Add(node); } } } } st.Save(outstream); // or st.WriteTo(xmlwriter);
source share