System.Xml.XmlReader.ReadSubtree Method

Returns a new XmlReader instance that can be used to read the current node, and all its descendants.

Syntax

public virtual XmlReader ReadSubtree ()

Returns

A new XmlReader instance set to ReadState.Initial. A call to the XmlReader.Read method positions the new XmlReader on the node that was current before the call to ReadSubtree method.

Remarks

XmlReader.ReadSubtree can be called only on element nodes. When the entire sub-tree has been read, calls to the Read method returns false. When the new XmlReader has been closed, the original XmlReader will be positioned on the EndElement node of the sub-tree. Thus, if you called the XmlReader.ReadSubtree method on the start tag of the book element, after the sub-tree has been read and the new XmlReader has been closed, the original XmlReader is positioned on the end tag of the book element.

You should not perform any operations on the original XmlReader until the new XmlReader has been closed. This action is not supported and can result in unpredictable behavior.

Note:

The XmlReader.ReadSubtree method is not intended to create a copy of the XML data that you can work with independently. Rather, it can be used create a boundary around an XML element. This is useful if you need to pass data to another component for processing and you wish to limit how much of your data the component can access. When you pass an XmlReader returned by the XmlReader.ReadSubtree method to another application, the application can access only that XML element, rather than the entire XML document.

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0