简体   繁体   English

XmlDocument-从字符串加载?

[英]XmlDocument - load from string?

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);
}

Instead if of loading the xml from a file, how do I load it from a string? 相反,如果不从文件加载xml,如何从字符串加载呢?

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

Where str is your XML string. 其中str是您的XML字符串。 See the MSDN article for more info. 有关更多信息,请参见MSDN文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM