Hi All, I have a problem which I think is sure easy enough that it would have been solved already. I am looking for some pointers here - I have an XML document like this: <root> <child> <element1>value1</element1> <element2>value2</element2> </child> <child> <element1>value1</element1> <element2>value2</element2> </child> ... ... </root> The <child> section like the one above, might repeat for hundreds of thousands of times. Since I am going to process this XML later for some other thing, I want to break it in smaller chunks, say XML documents of 5000 child records each. Is there a reasonable way to achieve this? I am using C# .Net 2.0 and Visual Studio 2005. Thanks in advance, Abhishek
Abhishek wrote: > The <child> section like the one above, might repeat for hundreds of > thousands of times. Since I am going to process this XML later for some > other thing, I want to break it in smaller chunks, say XML documents of 5000 > child records each. > > Is there a reasonable way to achieve this? I am using C# .Net 2.0 and Visual > Studio 2005. Use a combination of XmlReader and XmlWriter where you pull in the input XML with XmlReader and create a new document with XmlWriter for each chunk of 5000 child records. XmlWriter has a method WriteNode that takes an XmlReader http://msdn.microsoft.com/en-us/library/1wd6aw1b.aspx so you can simply copy those 'child' elements from the XmlReader to the XmlWriter. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
Thanks Martin, I will try to experiment with these and then come back if I have more questions. Regards Abhishek "Martin Honnen" wrote in message news:elryBgH2IHA.3920@TK2MSFTNGP02.phx.gbl... > Abhishek wrote: > >> The <child> section like the one above, might repeat for hundreds of >> thousands of times. Since I am going to process this XML later for some >> other thing, I want to break it in smaller chunks, say XML documents of >> 5000 child records each. >> >> Is there a reasonable way to achieve this? I am using C# .Net 2.0 and >> Visual Studio 2005. > > Use a combination of XmlReader and XmlWriter where you pull in the input > XML with XmlReader and create a new document with XmlWriter for each chunk > of 5000 child records. > XmlWriter has a method WriteNode that takes an XmlReader > http://msdn.microsoft.com/en-us/library/1wd6aw1b.aspx > so you can simply copy those 'child' elements from the XmlReader to the > XmlWriter. > > > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/