XML
What is the Syntax of making XML file in ASP.Net
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
TulasiRank #2,544 · 549 reputationPosted Oct 12, 2011, 8:34 PM EDT
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".