These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Use an XmlNodeReader?

This sample illustrates how to create and use an XmlNodeReader. An XmlNodeReader is a reader that provides fast, non-cached, forward-only access to XML data in an XmlNode. It has the ability to read an entire XML DOM tree or read from just a subtree. However, the XmlNodeReader does not support Document Type Definition (DTD) or schema validation, and therefore does not validate the XML it is reading.

This sample loads the books.xml into an XmlDocument, and then uses an XmlNodeReader to select a node and display the node value to the screen.

VB XmlNodeReader.exe
View Source

After creating and loading an XmlDocument with the books.xml file, the sample creates an XmlNodeReader that selects a single node from the XmlDocument and prints the node data to the screen. The sample then creates another XmlNodeReader that selects a different node to output to the screen.

		
Dim xmlDocument As New XmlDocument()
xmlDocument.Load(document)
...            
Console.WriteLine("Create an XmlNodeReader to show the third book ...")
Using xmlNodeReader As Xml.XmlNodeReader = New _
    Xml.XmlNodeReader(xmlDocument.SelectSingleNode("bookstore/book[3]"))
...            
Dim settings As New XmlWriterSettings()
settings.Indent = True
    Using writer As XmlWriter = XmlWriter.Create(Console.Out, settings)
        writer.WriteNode(xmlNodeReader, True)
    End Using
End Using
VB

Summary

  1. XmlNodeReader is a fast, non-cached, forward-only reader to access XML data in an XmlNode.
  2. Because an XmlNodeReader can be constructed with any XmlNode within the XmlDocument, XmlNodeReader provides a reader that reads only the subtree of a given node.




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.