System.Xml.XPath.XPathNavigator.ReadSubtree Method

Returns an System.Xml.XmlReader object that contains the current node and its child nodes.

Syntax

public virtual System.Xml.XmlReader ReadSubtree ()

Returns

An System.Xml.XmlReader object that contains the current node and its child nodes.

Remarks

When the System.Xml.XmlReader object is created with the current node and its child nodes, the System.Xml.XmlReader object's System.Xml.XmlReader.ReadState property is set to System.Xml.ReadState.Initial. When the System.Xml.XmlReader object's System.Xml.XmlReader.Read method is called for the first time, the System.Xml.XmlReader is moved to the current node of the System.Xml.XPath.XPathNavigator. The new System.Xml.XmlReader object continues to read until the end of the XML tree is reached. At this point, the System.Xml.XmlReader.Read method returns false and the System.Xml.XmlReader object's System.Xml.XmlReader.ReadState property is set to System.Xml.ReadState.EndOfFile.

Note:

Changing the position of the System.Xml.XmlReader object does not affect the position of the System.Xml.XPath.XPathNavigator.

Namespace declarations for the in-scope namespaces of the current node are not inserted into the XML stream provided to the System.Xml.XmlReader object.

Note:

This behavior differs from the XPathNavigator.WriteSubtree(System.Xml.XmlWriter) method.

This method creates the System.Xml.XmlReader object with specific reader settings, and the module that uses this method has no control over those settings. For example, the reader returned by this method prohibits processing Data Type Definitions (DTDs). If the reader attempts to read a file that uses a DTD, it will throw an error, System.Xml.XmlException. The message for the exception will be Unexpected DTD declaration.

You can change this behavior by implementing a custom System.Xml.XmlResolver that returns an System.Xml.XmlReader with the desired System.Xml.XmlReaderSettings.

Requirements

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