Regarding splitting Large xml files to smaller xm files

N

nikila

Hi,

I am trying to split large xml files to smaller xml files using c#.net. can
you please provide any sample code for this? I have to split the file if the
size is more than 10 MB.

Also, xml files after splitting should be valid xml. i am new to Csharp?


Thanks for your help

Nikila
 
S

Steven Nagy

Check out the Xml namespace in .NET.
Particularly the XmlDocument class.
I would load your XML doc into one of those, and then use the nodes
collection to move elements to new XmlDocuments.
Not sure how you can base it on size though. I guess you could write a
recursive function that checks all child nodes and their innerxml
properties, counting the chars.
 
N

Nicholas Paldino [.NET/C# MVP]

Nikila,

What I would do is read through the child elements of the document root.
As you read through them, I would write them to another file. After you
write each element, flush the writer so that the file is written to, then
check it's length. If you find that the file is too long, then you can trim
the file down (I would store the length of the file before that point).

You have to make sure that you write the document element for each file
that you write out as well, so after you write the fragments to one file,
make sure you write the closing document element, and then open a new file
with a new document element.

Hope this helps.
 
N

nikila

Hi,

Thank you for your reply. But can anybody provide me some sample code for
this.

Thanks,
Neelima

Nicholas Paldino said:
Nikila,

What I would do is read through the child elements of the document
root. As you read through them, I would write them to another file. After
you write each element, flush the writer so that the file is written to,
then check it's length. If you find that the file is too long, then you
can trim the file down (I would store the length of the file before that
point).

You have to make sure that you write the document element for each file
that you write out as well, so after you write the fragments to one file,
make sure you write the closing document element, and then open a new file
with a new document element.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


nikila said:
Hi,

I am trying to split large xml files to smaller xml files using c#.net.
can you please provide any sample code for this? I have to split the file
if the size is more than 10 MB.

Also, xml files after splitting should be valid xml. i am new to Csharp?


Thanks for your help

Nikila
 
S

Steven Nagy

You've been given classes and a couple of strategies for solving the
problem.
You'll have to actually complete the assignment on your own.
Most people here write code for a living and would prefer you to offer
money in exchange for the nicely packaged working solution you are
requesting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top