【问题标题】:XmlDocument - load from string?XmlDocument - 从字符串加载?
【发布时间】:2011-06-23 05:07:18
【问题描述】:
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,我该如何从字符串中加载呢?

【问题讨论】:

标签: c# asp.net xml json


【解决方案1】:
XmlDocument doc = new XmlDocument();
doc.LoadXml(str);

str 是您的 XML 字符串。请参阅MSDN article 了解更多信息。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-14
  • 1970-01-01
  • 2011-01-25
  • 1970-01-01
  • 1970-01-01
  • 2011-09-11
相关资源
最近更新 更多