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


0
6/27/2008 4:59:57 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
733 Views

Similar Articles

[PageSpeed] 27

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/
0
mahotrash (1778)
6/27/2008 5:05:26 PM
Thanks Martin,
I will try to experiment with these and then come back if I have more 
questions.

Regards
Abhishek

"Martin Honnen" <mahotrash@yahoo.de> 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/ 


0
6/27/2008 6:50:33 PM
Reply:

Similar Artilces:

Popup menu fails to notify ONE type of owner but not another
I have a problem with an owner-drawn popup menu class failing to notify its owner window when the user clicks on items in it. The strange thing is that it only fails to notify SOME owner but not others. If I supply a different owner for the TrackPopupMenu calls, it works fine. Call this class, "CPopup" To illustrate: 1. I have a CWnd derivative called CMyCtl. It has a button on it 2. The user presses the button and my control has a handler. 3. In the handler I instantiate a CPopup object and call TrackPopupMenu to bring up the menu.. The menu pops up just fine. void C...

Borders
I am creating a quote template in excel. To get the correct 'look and feel', I have used borders. This is fine if the quote can be contained on a single printed sheet, however, as soon as I go into a second page, I cannot get the border to recognise a page break. In other words, I have a series of vertical border lines but no horizontal border to signafy the end of one page and the start of another - Can this be automated? Many thanks! Excel 2002 ...

Mail merge existing document default folder
In Outlook 2002 Tools/Mail Merge allows me to select an existing document. The default folder is My Documents. We have our merge documents in a shared network folder. Is there a way to change the default folder so that the users don't have to browse thru numerous folders to get to the existing merge document? ...

Can you get line breaks in a text cell
I've got Excel XP and there is a form I'm creating that requires some free text input. Is there a way I can put in a line or para break into a cell (as you can in a cell of a word table). Can't easily use separate cells as the number of paras can vary. I could use word but then I lose the facility to use excel on all the cells that contain data. Any help or ideas would be appreciated. TIA Rob Just hit Alt-Enter which editing a cell to start a new line RFJ wrote: > I've got Excel XP and there is a form I'm creating that requires some free > text input. &...

Bug in XML signature??? Are there users than CAN answer????
Hi, I already posted two items - but no one seems to have the knowledge to help me out... In the mean time I found out the following: My existing signatures are testet using SignedXml sXml = new SignedXml(licenses); sXml.LoadXml(signature); RSA csp = RSA.Create(); csp.FromXmlString(context.GetSavedLicenseKey(typeof(MyLicense), Assembly.GetCallingAssembly())); sXml.SigningKey = csp; if (sXml.CheckSignature()) m_SignatureState = Signature.Valid; else ...

Joining Documents as one new document
I have eight, single page, Publisher documents - how do I join them together to form one, eight page document, please? Gareth Copy and paste -- JoAnn Paules MVP Microsoft [Publisher] "Gareth J Dykes" <firstname.lastname@btinternet.com> wrote in message news:cq535v$j6k$1@hercules.btinternet.com... >I have eight, single page, Publisher documents - how do I join them >together to form one, eight page document, please? > > Gareth > > I'm using XP BTW. Sorry but I need more help than this - nothing I paste does the job! Gareth "JoAnn Pau...

xml data in excel
I have designed an excel template with tabular format (row by row input) for user input. I have to make the validation for those input. My question is that is it possible to use XML schema as the input format template and use it for the data validation like normal XML validation. Could anyone suggest me how to do that?? Million thanks. ...

XSLT, XML to XML
Hello, I would like to transform this; <?xml version="1.0" encoding="utf-8" ?> <ProductList> <Product> <ID>1</ID> <Name>Gadget</Name> </Product> </ProductList> to this; <?xml version="1.0" encoding="utf-8" ?> <ProductList> <Product> <ID>1</ID> <Name>Gadget</Name> </Product> </ProductList> Basically I am hoping to use XslTransform and an XSLT stylesheet to change the format of some input XML so i...

copying a wksht fm one file wokbk to another
Actually I was told to copy the data figure from one wksheet of one file to another file workbook. I would like to know any vbscript could help me to copy that worksheet from that workbook to my subject workbook. By the way i have to carry out some addition calculations, is there any script that helps setting the original value filled in one of my worksheet as zero (coz' right now all figure are in 0ve figure) Urgent!! Please help! chermaine wrote: > Actually I was told to copy the data figure from one wksheet of one > file to another file workbook. > I would like to know any vb...

Page Breaks
When I add a page break on one page I get a paragragh return on the next page which brings down the copy on the page....How do I have a page break without the return on the following page? Unless the paragraph mark is before a table, you should be able to delete it. But you can work around this in any case by formatting the text on the desired new page as "Page break before." -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "designermom" <designermom@discussions.microsoft.com> wrote in message...

Printing 4 sheets on one page
Any way to print 4 sheets as one continuous printout? Right now it shows each page, even though its grouped, as a separate printout in print preview. Excel 97, yes 97! You have at least a couple of choices: #1. Insert a new sheet and copy the data from the 4 worksheets into this one and print from there (yech!). #2. Insert a new sheet and copy a picture of your data into this worksheet and print from there (yea!). Insert the new sheet Do this for each worksheet Select your range edit|copy back to the new sheet shift-edit|paste picture link (by pasting a picture link, the picture will...

Two word documents opened at once.
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Please help. I usually will have two or more word documents open at once.When I minimize, the document goes into my dock... which is right. But when I click to restore it..... it wants to open the document behind the current document, rather than on top. <br><br>I used to be able to restore the document and have it displayed immediately. Now I have to restore the document from my doc and then minimize the other document. Takes a lot of time. Please help me. Same here. Seems to be a problem of Word...

new xml file is larger than the original
i'm working on a windows application that will edit and create xml files from another application. the original file is 83k, the one created by my vb.net program is 153k but all i add is a new xmlelement when i use the other program and add a xmlelement is only increased the file to 85k. how come my application increased 70k in size and also added the <?xml version="1.0"?> when i didn't tell it to. how do i duplicated a xml file and only add the xml element that i want to insert. where did the extra 70k come from. thanks here is my code: Dim newEvtEnr...

Making 'Select Names' dialog box larger
Hi, In Outlook 2000, the 'Select Names' dialog box (when you compose an e-mail and click on the 'To' button to chose recipients) is ridiculously small and unable to be resized. So a lot of info (even the longer names in their entireity) are truncated. Is there any way to change the size of this dialog, it's really quite annoying. Thanks for any suggestions. Leigh Heydon lheydonNOSPAM@iprimus.com.au No. Not until Outlook 2003. -- Russ Valentine [MVP-Outlook] "Leigh Heydon <lheydonNOSPAM@iprimus.com.au>" <lheydon@gmail.com> wrote in message news:...

eConnect
What are the user defined fields for developers in the eConnect XML schemas used for? -- Cindy Cindy: Developers will typically populate these fields with data/values that they later use to populate their own custom tables (via a pre or post procedure). You would put a value say in the first user defined field and if the value is 1 then in a pre or post procedure they call their own custom stored procedure and if the value is 0 then they do not call their own customer stored procedure. That is probably the most common way people use these fields. Hope that helps some, JG "...

turn off document protection
I have a CD with a few documents on it and I need to turn off the protection that seems to be on the whole CD. I want to remove some documents totally and edit the main document. I have tried the Tools menu and there is no "Remove AutoProtect" or Remove Protect or anything on it, I have checked all the menus on that list. I tried removing the text in the entire document and it wouldn't save it that way either. Anyway. Any ideas? I have XP. The documents are all my own by the way. Vanayssa I suspect that the problem is that the documents are on a CD and has nothing ...

page break preview #3
I have created a new "sheet" in my workbook. My first sheet includes Page 1 to Page 22. I want my second sheet to start at Page 17, which I changed on the page setup page, however, the page break preview is still showing PAGE 1. How can I change this to show Page 17? VickiJo, If you're printing or previewing sheets separately, you'll get a starting page number of 1. If you're printint or previewing multiple sheets, it'll continue the page numbers from sheet to sheet. The First Page Number (File - Page Setup - Page tab) must be set to "Auto" for ...

"element is not declared" errors when validating xml from schema
I am writing a web application for job seekers, and am adding a section that allows administrators to upload jobs to the system via xml. I have used an xml schema to validate the xml they upload. The website runs on IIS5 using classic ASP, and the xml validation is done in a .NET component written in C# that is registered for COM interop on the webserver. I have a test application to test the .NET component, and that application does not give any errors, however, when I run it in the web application, it keeps coming back with errors on every element. It just started having problems today, so...

Moving Multiple Rows at one time
I have a worksheet that contains relevant data (I imported the data) in 2 rows; every 2 rows is a new incidence of data. Example: (row 1) Hold Flag (row 2) FIELD: YES/NO (Length=3) (row 3) Date (row 4) FIELD: DATE (Length=6) and so on. What I need, is for row 1 to be in column 1 and for row 2 to be in column 3 (same row) so that the data looks like this: Hold Flag <empty cell> FIELD: YES/NO (Length=3) Date <empty cell> FIELD: DATE (Length=6) Can anyone help me? Excel doesn't allow me to select and drag/drop multiple (every other) cells at a time. (As an added bonus, if...

How do I break a chart data range
Most values in my chart are under 200000 but I have one that's 1.3 million which makes the others look tiny and unreadable. Is there a way to break the range to show the large value and the smaller values closer together? Hi have a look at http://www.tushar-mehta.com/excel/newsgroups/broken_y_axis/index.html http://peltiertech.com/Excel/Charts/axes.html#Broken -- Regards Frank Kabel Frankfurt, Germany Tara wrote: > Most values in my chart are under 200000 but I have one that's 1.3 > million which makes the others look tiny and unreadable. Is there a > way to break the range...

more than one business reply
tried his as a reply & it bounced. Hi I use money y2k SB and do this. I designate revenue under 2 separate files (my wife & I both own businesses that we owned when we married; separate v community property). Example revenue-me & revenue-wife. Then I have sub-categories for types of revenue (sales, etc.) for each category. When setting up the txf file to export to TurboTax it sets up separate schedule c's. Actually, I'm doing 3 businesses this way; one for her & 2 for me; separate mine with the sub categories. Hope this helps! Lew "KEK" <anonymous@disc...

XML parser in MFC?
hi, Priyanka here. can we have XML parser in MFC? thanks and regards, Priyanka I've used the ExPat parser. There are many others. joe On 18 Dec 2005 21:12:12 -0800, "priya" <priyanka.khedekar@gmail.com> wrote: >hi, >Priyanka here. >can we have XML parser in MFC? > > >thanks and regards, >Priyanka Joseph M. Newcomer [MVP] email: newcomer@flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm I use Xerces, but I don't recommend it. Take a look at this one: http://www.firstobject.com/dn_markup.htm The...

inserting more than one column
What would the VBA code be to insert 6 columns to the left of Col A? I recorded a macro but I know there has to be a quick line of code that will do the same things rather than 10 lines of code from the macro recorder. Thank you. Hi Columns("A:F").Insert Shift:=xlToRight -- Regards Roger Govier "SITCFanTN" <SITCFanTN@discussions.microsoft.com> wrote in message news:BD9FA6CB-C861-4BCB-93C9-E98232636594@microsoft.com... > What would the VBA code be to insert 6 columns to the left of Col A? I > recorded a macro but I know there has to be...

Charting cells with the same data in them to one chart bar
I have several cells that all have a "total" of 1 adn like 5 with different totals, I want a way for the pie chart (or what ever chart) to graph the totals and all the ones with "1" to come up as 1 pie slice with all the data listed. 20037 Washington 1 30013 Conyers 1 30022 Alpharetta 1 30052 Loganville 1 30064 Marietta 1 30068 Marietta 1 30076 Roswell 1 30084 Tucker 1 30088 Stone Mountain 1 30092 Norcross 1 30108 Bowdon 1 30168 Austell 1 30263 Newnan 1 30306 Atlanta 1 30316 Atlanta 1 30318 Atlanta 1 30327 At...

Section Breaks
I inherited a 61 page document that has a table of contents. There is a section break that I want to delete. I would like to delete all the section breaks as it seems to make the page numbering start over. How can I do that? You don't have to delete the section breaks to make the page numbering continuous. For each section, in the Page Number Format dialog box, choose "Continue from previous section." To display the dialog box, first activate the header and footer area, for example by double-clicking the header. Then do the following: - Click the Format Page ...