XML
What is the Syntax of making XML file in ASP.Net
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
TulasiPosted Oct 13, 2011, 12:34 AM
XmlDocument xmldoc = new XmlDocument();
// declaration
XmlNode nodedeclaration = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, null, null);
xmldoc.AppendChild(nodedeclaration);
//Root Element : Article
XmlNode root = xmldoc.CreateElement("Articles");
xmldoc.AppendChild(root);
//create sub article
XmlNode subroot = xmldoc.CreateElement("Article");
root.AppendChild(subroot);
//create attribute
XmlAttribute subattr = xmldoc.CreateAttribute("version");
subattr.InnerText = "2.0";
subroot.Attributes.Append(subattr);
//create sub element
XmlElement subelement1 = xmldoc.CreateElement("AuthorName");
subelement1.InnerText = "XXX";
subroot.AppendChild(subelement1);
XmlElement subelement2 = xmldoc.CreateElement("Cost");
subelement2.InnerText = "500";
subroot.AppendChild(subelement2);
//save xml files
xmldoc.Save(Server.MapPath("XML_Files") + "//MyXMLFile.xml");
Please do not forget to mark "Accpeted Answer".