Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Add multiple records to xml file

Question posted by: ganesh22 (Banned) on July 17th, 2008 06:28 AM
Hi,
Code: ( text )
  1. xmlw = new XmlTextWriter("c:\\testing.xml",null);
  2.             xmlw.WriteStartDocument();
  3.             xmlw.WriteStartElement("Company");
  4.             xmlw.WriteStartElement("Software");
  5.             xmlw.WriteStartElement("Skills");
  6.             xmlw.WriteElementString("Microsoft", textBox1.Text);
  7.             xmlw.WriteElementString("Sun", textBox2.Text);
  8.             xmlw.WriteEndElement();
  9.             xmlw.WriteStartElement("Management");
  10.             xmlw.WriteElementString("Admin", textBox3.Text);
  11.             xmlw.WriteElementString("Assist", textBox4.Text);           
  12.             xmlw.WriteEndElement();
  13.             xmlw.WriteEndElement();
  14.             xmlw.WriteEndElement();
  15.             xmlw.WriteEndDocument();
  16.             xmlw.Close();

The above code is for creating an xml, its working fine now iam having two requirements based on above code
1)after writing (xmlw.Close()) xml i want to display that xml in text box
2) I want to add multiple records in that xmlfile bcoz it creatinng only one record then we added another record means its replacing the previous record
I want to add multiple records in xml how?
Last edited by acoder : July 20th, 2008 at 10:11 AM. Reason: Added [code] tags
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
acoder's Avatar
acoder
Site Moderator
10,700 Posts
July 20th, 2008
10:12 AM
#2

Re: Add multiple records to xml file
As a full member now, you should know that we expect your code to be posted in [CODE] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use the tags in future.

MODERATOR.

Reply
acoder's Avatar
acoder
Site Moderator
10,700 Posts
July 20th, 2008
10:14 AM
#3

Re: Add multiple records to xml file
Quote:
Originally Posted by ganesh22
The above code is for creating an xml, its working fine now iam having two requirements based on above code
1)after writing (xmlw.Close()) xml i want to display that xml in text box
2) I want to add multiple records in that xmlfile bcoz it creatinng only one record then we added another record means its replacing the previous record
I want to add multiple records in xml how?
This is not an XML question really. This will be better answered in a language-specific forum (.NET I presume).

Reply
jkmyoung's Avatar
jkmyoung
Moderator
765 Posts
July 21st, 2008
01:53 PM
#4

Re: Add multiple records to xml file
1. Questions:
Do you really need to save the xml in a file, as opposed to some runtime memory object, perhaps as a string even?

If so, you could onClose, create a function which reads the text from the xml file and puts it into the textBox. However this seems like more work than necessary. It'd be easier if you had your XmlTextWriter write to a stringBuffer or stream, and then output the string to both the xml file and the textBox.

2. You need to create a function to read the xml you've written, eg an XmlReader.
After reading the xml in, you'd have a loop that rewrites the data to the new result as it reads it in from the old. Event style input/output is definitely the way to go, (eg the way you already have it by using XmlTextWriter). DOM would be overkill.

Reply
Reply
Not the answer you were looking for? Post your question . . .
180,792 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top XML Forum Contributors