开发者

XmlDocument - load from string?

开发者 https://www.devze.com 2023-02-09 08:09 出处:网络
protected void Page_Load(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); try {开发者_StackOverflow社区
protected void Page_Load(object sender, EventArgs e)
{
    XmlDocument doc = new XmlDocument();
    try
    {开发者_StackOverflow社区
        string path = Server.MapPath(".");
        doc.Load(path+"whatever.xml");
    }
    catch (Exception ex)
    {
        lblError.Text = ex.ToString();
        return;
    }

    // Convert XML to a JSON string
    string JSON = XmlToJSON(doc);

    // Replace \ with \\ because string is being decoded twice
    JSON = JSON.Replace(@"\", @"\\");

    // Insert code to process JSON at end of page
    ClientScriptManager cs = Page.ClientScript;
    cs.RegisterStartupScript(GetType(), "SpaceJSON", "space_processJSON('" + JSON + "');", true);
}

Instead if of loading the xml from a file, how do I load it from a string?


XmlDocument doc = new XmlDocument();
doc.LoadXml(str);

Where str is your XML string. See the MSDN article for more info.

0

精彩评论

暂无评论...
验证码 换一张
取 消