Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlTextReader Constructor (TextReader)

Initializes a new instance of the XmlTextReader class with the specified TextReader.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
'Declaration
Public Sub New ( _
	input As TextReader _
)

Parameters

input
Type: System.IO.TextReader

The TextReader containing the XML data to read.

NoteNote

In the .NET Framework 2.0 release, the recommended practice is to create XmlReader instances using the XmlReader.Create method. This allows you to take full advantage of the new features introduced in this release. For more information, see Creating XML Readers.

It is assumed that the TextReader is already set to the correct encoding. This is used by clients that have already read some things from the stream in a multi-part MIME scenario.

The following example loads an XML string into the XmlTextReader object using the StringReader class.

Imports System
Imports System.IO
Imports System.Xml

public class Sample 

  public shared sub Main()

    Dim xmlData as string 
    xmlData = "<book>" & _
              "  <title>Oberon's Legacy</title>" & _
              "  <price>5.95</price>" & _
              "</book>" 

    ' Create the reader. 
    Dim reader as XmlTextReader = new XmlTextReader(new StringReader(xmlData))
    reader.WhitespaceHandling = WhitespaceHandling.None

    ' Display each element node.
    while reader.Read()
       select case reader.NodeType
         case XmlNodeType.Element
           Console.Write("<{0}>", reader.Name)
         case XmlNodeType.Text
           Console.Write(reader.Value)
         case XmlNodeType.EndElement
           Console.Write("</{0}>", reader.Name)
       end select       
    end while           

    ' Close the reader.
    reader.Close()       
  end sub
end class

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.