Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Breaking larger xml document into smaller ones

Question posted by: Abhishek (Guest) on June 27th, 2008 07:20 PM
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 <childsection 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


Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
June 27th, 2008
07:20 PM
#2

Re: Breaking larger xml document into smaller ones
Abhishek wrote:
Quote:
The <childsection 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/

Abhishek's Avatar
Abhishek
Guest
n/a Posts
June 27th, 2008
07:20 PM
#3

Re: Breaking larger xml document into smaller ones
Thanks Martin,
I will try to experiment with these and then come back if I have more
questions.

Regards
Abhishek

"Martin Honnen" <mahotrash@yahoo.dewrote in message
news:elryBgH2IHA.3920@TK2MSFTNGP02.phx.gbl...
Quote:
Abhishek wrote:
>
Quote:
>The <childsection 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/




 
Not the answer you were looking for? Post your question . . .
189,870 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors