XmlDocument - स्ट्रिंग से लोड?


88
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 लोड करने के बजाय, मैं इसे स्ट्रिंग से कैसे लोड करूं?


3
XmlDocumentकक्षा को देखो । आप इसे बहुत जल्दी समझ लेंगे।
जॉन सॉन्डर्स

जवाबों:


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

strआपका XML स्ट्रिंग कहां है अधिक जानकारी के लिए MSDN लेख देखें ।


नए XmlDocument () {InnerXml = str} के बारे में क्या?
एमके

मुझे लगता LoadXml()है कि सिर्फ सेटिंग करने से ज्यादा होता है InnerXmlreferenceource.microsoft.com/#System.Xml/System/Xml/Dom/…
Vinicius Brasil
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.