|
-
December 19th, 2011, 08:45 AM
#1
Adding Data in XML files.
I have got an Xml like below. I want to "add" data in it. Tried alot of forums.....none helped. Hope I get some here.
eg.<?xml version="1.0" encoding="us-ascii"?>
<!--Version 5.0.0.0 - 4/12/2011-->
<SalesReport>
<ProductList>
</ProductList>
<Customers>
<Customer ID="47530">
<Name>Mr. Andrews</Name>
<Address>27/A, Wimpole Street</Address>
<Membersince>1/11/11</Membersince>
</Customer>
</Customers>
</SalesReport>
I want to make it-
<!--Version 5.0.0.0 - 4/12/2011-->
<SalesReport>
<ProductList>
</ProductList>
<Customers>
<Customer ID="47530">
<Name>Mr. Andrews</Name>
<Address>27/A, Wimpole Street</Address>
<Membersince>1/11/11</Membersince>
</Customer>
<Customer ID="47530">
<Name>Mr. Smith</Name>
<Address>41/B, Cruise Street</Address>
<Membersince>23/04/11</Membersince>
</Customer>
</Customers>
</SalesReport>
I have to do it in vb.net and have got around 2 weeks before I submit this. Please help me......
-
December 19th, 2011, 03:46 PM
#2
Re: Adding Data in XML files.
Have you looked at any documentation? There is an XMLReader() class that helps. You should search form VB.NET CODE and then your terms that you want to search for http://code.msdn.microsoft.com/vb2010samples
-
December 22nd, 2011, 04:55 AM
#3
Re: Adding Data in XML files.
well I want to write more, and all documentations for xmlreader and xmlwriter overwrite the xml.
-
December 22nd, 2011, 02:36 PM
#4
Re: Adding Data in XML files.
Because that's the way you HAVE to do it, when you add or remove. Why re-invent the wheel?
-
December 22nd, 2011, 04:11 PM
#5
Re: Adding Data in XML files.
Well clearly the read method does not overwrite anything, it simply reads the data.
It is possible to make a change to an XML or any other file without overwriting but in a case such as XML there is no real point in doing so.
You would have to know where in the file you are going to write data and how many bytes you are going to write. If you are replacing something that is currently there then you have to know the size of what is currently there as well. If the 2 pieces of data are the same size then you can write the new data to the proper location using a binary method. If however the data is of different lenght then you need to do something about the difference. For instance you may read the remainder of the file into memory then write you changed data to the correct location followed by a write of the remainder of the data which would give you a valid output file. You would not be overwriting the file but you would be overwriting a portion of it. how much would depend on where the data you need to change resides in the file.
Again there is no point in doing something like this unless you are just doing it to learn how to handle files at this level. Typically when dealing with any text file that has variable length records you would overwrite the existing file with a modified version, in most cases this is both the fastest and simpliest way to do it. You can of course make a backup of the original before doing so.
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|