Team Fly |
Page 487
In .NET, an XML document can be loaded using the Load method (you pass an argument describing the source, which can be a disk file, a stream, an XMLReader, or a TextReader object). Or you can use the LoadXML method to load a literal string, or string variable, into your document.
Start a new VB.NET Windows project, and add these namespaces:
Imports System.Xml Imports System.Xml.Xsl
To see how to create an XML document, then load a literal string into it, type in the code in Listing 17.3.
LISTING 17:3 LOADING A LITERAL STRING INTO AN XML DOCUMENT |
Private Sub Form1_Load(ByVal sender As System.Object, _ |
Here's the result when this code is executed:
<Cookie><Name>Francine Cerance</Name></Cookie> <Name>Francine Cerance</Name>
To see how to load XML from a file, make the following change to the previous example. Change LoadXml to Load, and replace the string argument with the path to an XML file:
XMLdoc.Load("c:\books.xml")
Press F5 and you'll see two long lines of data in the Output window. The only difference between these lines is that the first line includes the <catalog> tags because it displays the outer XML.
Team Fly |