Monday, October 19, 2009

Reading large XML File

Here is the code for reading large XML file, this code works faster than opening the file in any other application.

XmlTextReader xtrInput;
XmlDocument xdItem;
xtrInput = new XmlTextReader("sample.xml");
int i = 0;
while(xtrInput.Read())
{
while (xtrInput.NodeType == XmlNodeType.Element && xtrInput.Name.ToLower() == "record")
{
i = i + 1;
xdItem = new XmlDocument();
xdItem.LoadXml(xtrInput.ReadOuterXml());
xdItem.Save("file" + i.ToString() + ".xml");
}
}
xtrInput.Close();


No comments: