469,312 Members | 2,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

Add multiple records to xml file

Hi,
Expand|Select|Wrap|Line Numbers
  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();
  17.  
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?
Jul 17 '08 #1
3 4719
acoder
16,027 Expert Mod 8TB
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.
Jul 20 '08 #2
acoder
16,027 Expert Mod 8TB
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).
Jul 20 '08 #3
jkmyoung
2,057 Expert 2GB
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.
Jul 21 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.