Click here to Skip to main content
15,909,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to create an xml file during runtime of an asp site...

thanks in advance...
Posted

public void Xml_Insert()
   {

           XmlDocument xmlDoc = new XmlDocument();

           // Write down the XML declaration
           XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

           // Create the root element
           XmlElement rootNode = xmlDoc.CreateElement("CategoryList");
           xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
           xmlDoc.AppendChild(rootNode);

           // Create a new <Category> element and add it to the root node
           XmlElement parentNode = xmlDoc.CreateElement("Category");

           // Set attribute name and value!
           parentNode.SetAttribute("ID", "01");

           xmlDoc.DocumentElement.PrependChild(parentNode);

           // Create the required nodes
           XmlElement mainNode = xmlDoc.CreateElement("MainCategory");
           XmlElement descNode = xmlDoc.CreateElement("Description");
           XmlElement activeNode = xmlDoc.CreateElement("Active");

           // retrieve the text
           XmlText categoryText = xmlDoc.CreateTextNode("XML");
           XmlText descText = xmlDoc.CreateTextNode("This is a list my XML articles.");
           XmlText activeText = xmlDoc.CreateTextNode("true");

           // append the nodes to the parentNode without the value
           parentNode.AppendChild(mainNode);
           parentNode.AppendChild(descNode);
           parentNode.AppendChild(activeNode);

           // save the value of the fields into the nodes
           mainNode.AppendChild(categoryText);
           descNode.AppendChild(descText);
           activeNode.AppendChild(activeText);

           // Save to the XML file
           xmlDoc.Save(Server.MapPath("categories.xml"));

           Response.Write("XML file created");

   }


use this function to create temp xml file on client machine.
 
Share this answer
 
v2
Check this[^]


and

This[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900