I need to iterate through a large XML file (~ 2 GB) and selectively copy specific nodes to one or more separate XML files.
My first thought is to use XPath to iterate through the appropriate nodes and for each node test to which another node file should be copied, for example:
var doc = new XPathDocument(@"C:\Some\Path.xml"); var nav = doc.CreateNavigator(); var nodeIter = nav.Select("//NodesOfInterest"); while (nodeIter.MoveNext()) { foreach (Thing thing in ThingsThatMightGetNodes) { if (thing.AllowedToHaveNode(nodeIter.Current)) { thing.WorkingXmlDoc.AppendChild(... nodeIter.Current ...); } } }
In this implementation, Thing defines a public System.Xml.XmlDocument WorkingXmlDoc to hold nodes in AllowedToHave() . However, I do not understand how to create a new XmlNode, which is a copy of nodeIter.Current.
If there was a better approach, I would also be happy to hear it.
source share