C# XmlDocument-从字符串加载?

C# XmlDocument-从字符串加载?,c#,asp.net,xml,json,C#,Asp.net,Xml,Json,如果不从文件加载xml,如何从字符串加载 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) {

如果不从文件加载xml,如何从字符串加载

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);
}
其中
str
是XML字符串。有关更多信息,请参阅。

查阅。你很快就会明白的。
LoadXml()
-那新的XmlDocument(){InnerXml=str}呢?我认为
LoadXml()
不仅仅是设置
InnerXml
XmlDocument doc = new XmlDocument();
doc.LoadXml(str);