Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XmlDocument - load from string?

Tags:

json

c#

xml

asp.net

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?

like image 300
001 Avatar asked Feb 08 '11 04:02

001


People also ask

How do I load a string in XML?

To load XML from a string To populate an XML literal such as an XElement or XDocument object from a string, you can use the Parse method. The following code example shows the use of the XDocument. Parse(String) method to populate an XDocument object with XML from a string.

How do I load an XML file?

Use XmlDocument. Load() method to load XML from your file. Then use XmlDocument. InnerXml property to get XML string.

What is the difference between XDocument and XmlDocument?

XDocument is from the LINQ to XML API, and XmlDocument is the standard DOM-style API for XML. If you know DOM well, and don't want to learn LINQ to XML, go with XmlDocument . If you're new to both, check out this page that compares the two, and pick which one you like the looks of better.

How do I read an XML string in Java?

In this article, you will learn three ways to read XML files as String in Java, first by using FileReader and BufferedReader, second by using DOM parser, and third by using open-source XML library jcabi-xml.


1 Answers

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

Where str is your XML string. See the MSDN article for more info.

like image 159
wsanville Avatar answered Oct 14 '22 20:10

wsanville