Create XML with LoadXml(string) in ASP.NET

using System;
using System.Xml;

public partial class create_xml_string : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
    {
      string xmlString = "<?xml version='1.0' encoding='UTF-8'?>";
      xmlString += "<products>";
        xmlString += "<product id='p3'>";
          xmlString += "<name>Alpha</name>";
          xmlString += "<price>1200</price>";
          xmlString += "<stock>19</stock>";
          xmlString += "<country>Germany</country>";
        xmlString += "</product>";
      xmlString += "</products>";

      XmlDocument doc = new XmlDocument();
      doc.LoadXml(xmlString);
      doc.Save(Server.MapPath("products-string.xml"));

      Response.Redirect("products-string.xml"); // load file in browser
    }
}

你可能感兴趣的:(xml,String,net,create,loadxml)