473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Regarding splitting Large xml files to smaller xm files

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
Jul 13 '06 #1
4 4411
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.

nikila wrote:
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
Jul 13 '06 #2
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]
- mv*@spam.guard.caspershouse.com
"nikila" <ni*****@yahoo.comwrote in message
news:OE*************@TK2MSFTNGP05.phx.gbl...
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

Jul 13 '06 #3
Hi,

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

Thanks,
Neelima

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:ef**************@TK2MSFTNGP04.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"nikila" <ni*****@yahoo.comwrote in message
news:OE*************@TK2MSFTNGP05.phx.gbl...
>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


Jul 13 '06 #4
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.

Jul 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William Ahern | last post by:
I'm looking for resources on splitting and merging XML trees. Specifically, on methods to pare large XML documents into smaller documents which can be merged later. Off of the top of my head, I...
6
by: afh3 | last post by:
Create a setup.exe deployment package and try to execute it on a server with 2TB of disk space. The installer will report that the drive is negative in size, and will therefore refuse to install. ...
11
by: CSN | last post by:
Is it possible to iterate over an array in plpgsql? Something like: function insert_stuff (rel_ids int) .... foreach rel_ids as id insert into table (rel_id, val) values (id, 5);
11
by: MM | last post by:
Hi I have never written any C programs before, but it seems that I need to do so now. Hope some of you out there can spend a few minutes and help me by writing a simple example of something...
1
by: Kevin A. | last post by:
Hi all, I'm trying to make a little game in VB.NET that uses sprites (bitmaps) with a fixed size, currently 32x32 pixels. Now I was thinking: when I want to include objects in my game...
5
by: hecuba007 | last post by:
My apologies if this question has been asked before .. I would like to split large files into smaller chunks for uploading to php for re-assembly on the server. Is there a (relatively) simple...
2
by: Jenny | last post by:
Hello All! I have a long XML file that I should transmit to other computer using http. Problem is that the whole XML Document is too large for one transmitting. What is the nicest way to...
2
by: Jenny | last post by:
Hello All! I have a long XML file that I should transmit to other computer using http. Problem is that the whole XML Document is too large for one transmitting. What is the nicest way to...
25
by: tekctrl | last post by:
Anyone: I have a simple MSAccess DB which was created from an old ASCII flatfile. It works fine except for something that just started happening. I'll enter info in a record, save the record,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.