If you want to load existing XML into an XmlDocument, there are two very similar methods that can be used: Load and LoadXml. The Load method can load an XML document from a Stream, TextReader, or XmlReader. The LoadXml method can load the XML only from a string. Listing 11.2 shows how to use both Load methods as well as create an XmlDocument.
C# // Load the document from a stream XmlDocument doc = new XmlDocument(); doc.Load(new FileReader("bogus.xml", FileMode.Open)); // Load the document from a TextReader doc = new XmlDocument(); doc.Load(new StreamReader("bogus.xml")); // Load the document from a XmlReader doc = new XmlDocument(); doc.Load(new XmlTextReader("bogus.xml"); // Load the document for an XML string XmlDocument doc = new XmlDocument(); doc.LoadXml("<root><child/></root>"); VB ' Load the document from a stream Dim doc As New XmlDocument() doc.Load(New FileReader("bogus.xml", FileMode.Open)) ' Load the document from a TextReader doc = New XmlDocument() doc.Load(New StreamReader("bogus.xml")) ' Load the document from a XmlReader doc = New XmlDocument() doc.Load(New XmlTextReader("bogus.xml") ' Load the document for an XML string doc = New XmlDocument() doc.LoadXml("<root><child/></root>") |
3.144.30.236