gpt4 book ai didi

c# - XmlDocument - 从字符串加载?

转载 作者:IT老高 更新时间:2023-10-28 12:42:50 26 4
gpt4 key购买 nike

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,我该如何从字符串中加载呢?

最佳答案

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

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

关于c# - XmlDocument - 从字符串加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4929653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com