XmlReader.Create Method (TextReader)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Creates a new XmlReader instance with the specified TextReader.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public Shared Function Create ( _
    input As TextReader _
) As XmlReader
public static XmlReader Create(
    TextReader input
)

Parameters

  • input
    Type: System.IO.TextReader
    The TextReader from which to read the XML data. Because a TextReader returns a stream of Unicode characters, the encoding specified in the XML declaration is not used by the XmlReader to decode the data stream.

Return Value

Type: System.Xml.XmlReader
An XmlReader object to read the XML data.

Exceptions

Exception Condition
NullReferenceException

The input value is nulla null reference (Nothing in Visual Basic).

Remarks

An XmlReaderSettings object with default settings is used to create the reader. If you wish to specify the features to support on the created reader, use the overload that takes an XmlReaderSettings object as one of its arguments, and pass in an XmlReaderSettings object with the correct settings.

Examples



Dim output As New StringBuilder()


Dim xmlString As String = _
            "<root>" & _
            "<stringValue><!--comment-->" & _
            "<?some pi?>text value of the element." & _
            "</stringValue>" & _
            "<longValue>270000000000001</longValue><number>0</number>" & _
            "<double>2E10</double><date>2003-01-08T15:00:00-00:00</date>" & _
            "</root>"

Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))
    reader.ReadToFollowing("longValue")
    Dim number As Long = reader.ReadElementContentAsLong()
    output.AppendLine(number.ToString())
End Using

OutputTextBlock.Text = output.ToString()



StringBuilder output = new StringBuilder();

String xmlString =
    @"<root>
    <stringValue>
    <!--comment-->
    <?some pi?>
        text value of the element.
    </stringValue>
    <longValue>270000000000001</longValue>
    <number>0</number>
    <double>2E10</double>
    <date>2003-01-08T15:00:00-00:00</date>
</root>";

using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
    reader.ReadToFollowing("longValue");
    long number = reader.ReadElementContentAsLong();
    output.AppendLine(number.ToString());
}

OutputTextBlock.Text = output.ToString();

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.