XmlReader::MoveToContent Method ()
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.
Assembly: System.Xml (in System.Xml.dll)
| Exception | Condition |
|---|---|
| XmlException | Incorrect XML encountered in the input stream. |
| InvalidOperationException | 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.” |
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.
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(); }
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" [<!ENTTIY p "123.4">]><price>&p;</price>
and
<!-- some test comment --><?processing instruction?><price>123.4</price>
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1