I just started using VS2010 and C#.
I’m trying to create an app which takes values from two textboxes and adds it to an existing xml file.
eg.
Text Box 1 Text Box 2
---------- ----------
A B
C D
E F
I want the resultant xml file to be like this.
<root>
<element>
<Entry1>A</Entry1>
<Entry2>B</Entry2>
</element>
</root>
and so on…
Can this be done using C# ??
I’m unable to add the entries alternatively i.e. Entry1 should contain Text Box 1 line #1 and Entry2 Text Box 2 line #1.
Any help would be appreciated.
Thanks
You need to split the string retrieved from the text box based on the
new linelike this:Once you have values split for each text box, you can use System.xml.linq.xdocument class and loop through the values that you retrieve above.
Something like this:
You can retrieve a xml document using a linq query or save it in an xml file using the
Savemethod ofXDocumentThe below code will give you a string of
XMLdata from the textboxes:You can then insert the code to an existing xml document. Follow: How can I build XML in C#? and How to change XML Attribute