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
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章