Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Fri, 27 Jun 2008 22:29:57 +0530,    group: microsoft.public.dotnet.xml        back       


Breaking larger xml document into smaller ones   
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
date: Fri, 27 Jun 2008 22:29:57 +0530   author:   Abhishek

Re: Breaking larger xml document into smaller ones   
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/
date: Fri, 27 Jun 2008 19:05:26 +0200   author:   Martin Honnen

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"  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/
date: Sat, 28 Jun 2008 00:20:33 +0530   author:   Abhishek

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us