XmlReader.MoveToContent Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Checks whether the current node is a content (non-white space text, CDATA
, Element
, EndElement
, EntityReference
, or EndEntity
) node. If the node is not a content node, the reader skips ahead to the next content node or end of file. It skips over nodes of the following type: ProcessingInstruction
, DocumentType
, Comment
, Whitespace
, or SignificantWhitespace
.
public:
virtual System::Xml::XmlNodeType MoveToContent();
public virtual System.Xml.XmlNodeType MoveToContent ();
abstract member MoveToContent : unit -> System.Xml.XmlNodeType
override this.MoveToContent : unit -> System.Xml.XmlNodeType
Public Overridable Function MoveToContent () As XmlNodeType
The NodeType of the current node found by the method or XmlNodeType.None
if the reader has reached the end of the input stream.
Incorrect XML encountered in the input stream.
An XmlReader method was called before a previous asynchronous operation finished. In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."
This is useful when you want to write code that can skip over random XML markup without breaking. For example, suppose you have the following code:
if ( reader->MoveToContent() == XmlNodeType::Element &&
reader->Name->Equals( "price" ) )
{
_price = reader->ReadString();
}
if (reader.MoveToContent() == XmlNodeType.Element && reader.Name == "price")
{
_price = reader.ReadString();
}
If reader.MoveToContent() = XmlNodeType.Element And reader.Name = "price" Then
_price = reader.ReadString()
End If
This code can handle the following inputs without breaking:
<price>123.4</price>
and
<?xml version="1.0"><!DOCTYPE price SYSTEM
"abc"><price>123.4</price>
and
<?xml version="1.0"><!DOCTYPE price SYSTEM "abc"
[<!ENTITY p
"123.4">]><price>&p;</price>
and
<!-- some test comment --><?processing
instruction?><price>123.4</price>
If the current node is an attribute node, this method moves the reader back to the element that owns the attribute.
For the asynchronous version of this method, see MoveToContentAsync.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: