AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

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

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\Xml\XmlNodeReader\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]

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.


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.