Loading the XML DOM

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.

Listing 11.2.
 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 ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.