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
类,您很快就能理解它。 - John SaundersLoadXml()
- http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspxLoadXml()
- http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspx - Dan Atkinson