//XML File Creation
XmlDocument doc = new XmlDocument();
// XML declaration
XmlNode declaration = doc.CreateNode(XmlNodeType.XmlDeclaration, null, null);
doc.AppendChild(declaration);
// Root element: article
XmlElement root = doc.CreateElement("article");
doc.AppendChild(root);
// Sub-element: author
XmlElement author = doc.CreateElement("author");
author.InnerText = "Faisal Khan";
root.AppendChild(author);
// Attribute: isadmin
XmlAttribute isadmin = doc.CreateAttribute("isadmin");
isadmin.Value = "true";
author.Attributes.Append(isadmin);
// Sub-element: title
XmlElement title = doc.CreateElement("title");
title.InnerText = "Sample XML Document";
root.AppendChild(title);
// Sub-element: body (CDATA)
XmlElement body = doc.CreateElement("body");
XmlNode cdata = doc.CreateCDataSection("This is the body of the article.");
body.AppendChild(cdata);
root.AppendChild(body);
doc.Save(Server.MapPath("../text.xml"));//it makes xml file in root folder
//End of XML Creation
Wednesday, July 14, 2010
Subscribe to:
Comments (Atom)

