ReadFrom Method

XNode.ReadFrom Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Creates an XNode from an XmlReader.

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

'Declaration
Public Shared Function ReadFrom ( _
	reader As XmlReader _
) As XNode

Parameters

reader
Type: System.Xml.XmlReader
An XmlReader positioned at the node to read into this XNode.

Return Value

Type: System.Xml.Linq.XNode
An XNode that contains the node and its descendant nodes that were read from the reader. The runtime type of the node is determined by the node type (NodeType) of the first node encountered in the reader.

ExceptionCondition
InvalidOperationException

The XmlReader is not positioned on a recognized node type.

XmlException

The underlying XmlReader throws an exception.

You can use this method to write a method that returns a collection of nodes, yielding each node as the node is read from the reader. This method enables you to process arbitrarily large XML files with a very small memory footprint.

The reader that you pass to this method might throw exceptions. ReadFrom does not catch all exceptions thrown by the reader; the unhandled exceptions bubble up to the code that called ReadFrom. In particular, your code should be prepared to handle XmlException.

For an example of how to stream a more complex document, see How to: Stream XML Fragments with Access to Header Information in the .NET Framework documentation.

Certain standard query operators, such as OrderBy, iterate their source, collect all of the data, sort it, and then finally yield the first item in the sequence. If you use a query operator that materializes its source before yielding the first item, you will not retain a small memory footprint.

For an example of using LINQ to XML to transform extremely large XML documents while maintaining a small memory footprint, see How to: Perform Streaming Transform of Large XML Documents in the .NET Framework documentation.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft