Hi,
Please refer below code.
C#
XmlDocument doc = new XmlDocument();
XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
XmlElement root = doc.DocumentElement;
doc.InsertBefore(xmlDeclaration, root);
XmlElement Contacts = doc.CreateElement(string.Empty, "Contacts", string.Empty);
doc.AppendChild(Contacts);
XmlElement contact = doc.CreateElement(string.Empty, "contact", string.Empty);
Contacts.AppendChild(contact);
XmlElement id = doc.CreateElement(string.Empty, "id", string.Empty);
XmlText idText = doc.CreateTextNode("1");
id.AppendChild(idText);
contact.AppendChild(id);
XmlElement name = doc.CreateElement(string.Empty, "name", string.Empty);
XmlText nameText = doc.CreateTextNode("Vedh");
name.AppendChild(nameText);
contact.AppendChild(name);
XmlElement contactNo = doc.CreateElement(string.Empty, "contactno", string.Empty);
XmlText conatactNoText = doc.CreateTextNode("9876543210");
contactNo.AppendChild(conatactNoText);
contact.AppendChild(contactNo);
XmlElement address = doc.CreateElement(string.Empty, "address", string.Empty);
XmlText addressText = doc.CreateTextNode("HYD");
address.AppendChild(addressText);
contact.AppendChild(address);
doc.Save("D:\\document.xml");
C# Linq
XDocument docLinq = new XDocument(new XElement("Contacts",
new XElement("contact",
new XElement("name", "Vedh"),
new XElement("contactno", "9876543210"),
new XElement("address", "HYD"))));
docLinq.Save("D:\\document.xml");
OutPut
<?xml version="1.0" encoding="UTF-8"?>
<Contacts>
<contact>
<id>1</id>
<name>Vedh</name>
<contactno>9876543210</contactno>
<address>HYD</address>
</contact>
</Contacts>
Create using Javascript
http://stackoverflow.com/questions/6066837/how-to-write-data-from-form-in-html-to-xml-with-javascript
Read Xml Documents using below links
- How to read and bind XML file to GridView in ASP.Net
- Read XML as string and display it on ASP.Net Page
- Read Attributes of XML loaded in DataSet using C#
I hope this will help you out.