XmlDocument-从字符串加载?


88
protected void Page_Load(object sender, EventArgs e)
{
    XmlDocument doc = new XmlDocument();
    try
    {
        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);
}

相反,如果不从文件加载xml,如何从字符串加载呢?


3
查找XmlDocument班级。您很快就会发现自己的问题。
约翰·桑德斯

Answers:


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.