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 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>") 


Microsoft.NET Compact Framework Kick Start
Microsoft .NET Compact Framework Kick Start
ISBN: 0672325705
EAN: 2147483647
Year: 2003
Pages: 206

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net