| View previous topic :: View next topic |
| Author |
Message |
Dileep
Joined: 12 Sep 2007 Posts: 77
|
Posted: Wed Aug 06, 2008 7:10 am Post subject: How to insert new element in to XML file |
|
|
Hi,
I have created XML file, through my application i need to insert new element in to XML file can any one post sample code.
Regards,
Dileep. |
|
| Back to top |
|
 |
venkat
Joined: 21 Aug 2007 Posts: 164
|
Posted: Wed Aug 06, 2008 7:20 am Post subject: |
|
|
Hi Dileep,
If you have posted your XML file, i can given sample code which is related to XML file.
VENKAT ... |
|
| Back to top |
|
 |
Dileep
Joined: 12 Sep 2007 Posts: 77
|
Posted: Wed Aug 06, 2008 7:27 am Post subject: |
|
|
Hi venkat,
thanks for the quick response, i am posting my XML file
Employee.xml
<?xml version="1.0" encoding="utf-8" ?>
<Employees>
<Employee Name="James" Sal="10000">
</Employee>
<Employee Name="David" Sal="8000">
</Employee>
</Employees> |
|
| Back to top |
|
 |
venkat
Joined: 21 Aug 2007 Posts: 164
|
Posted: Wed Aug 06, 2008 7:33 am Post subject: |
|
|
Here is the sample code..
FileStream fs = new FileStream(@"Employee.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Specify the path of the XML file
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(fs);
// Adding new element to Employee xml file
XmlElement XML_Ele = xmldoc.CreateElement("Employee");
XML_Ele.SetAttribute("Name", Dileep);
XML_Ele.SetAttribute("Sal", 12000);
xmldoc.DocumentElement.AppendChild(XML_Ele);
xmldoc.Save(@"Employee.xml"); // Saving the file |
|
| Back to top |
|
 |
|