The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
This topic has not yet been rated - Rate this topic

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.

[Visual Basic]
Public Overridable Function MoveToContent() As XmlNodeType
public virtual XmlNodeType MoveToContent();
public: virtual XmlNodeType MoveToContent();
public function MoveToContent() : XmlNodeType;

Return Value

The NodeType of the current node found by the method or XmlNodeType.None if the reader has reached the end of the input stream.


Exception Type Condition
XmlException Incorrect XML encountered in the input stream.


If the current node is an attribute node, this method moves the reader back to the element that owns the attribute.


[Visual Basic, C#, C++] 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:

[Visual Basic] 
If reader.MoveToContent() = XmlNodeType.Element And reader.Name = "price" Then
    _price = reader.ReadString()
End If

if (reader.MoveToContent() == XmlNodeType.Element && reader.Name == "price") 
    _price = reader.ReadString();

if (reader->MoveToContent() == XmlNodeType::Element && reader->Name->Equals(S"price")) 
    _price = reader->ReadString();

[Visual Basic, C#, C++] This code can handle the following inputs without breaking:

[Visual Basic, C#, C++] <price>123.4</price>

[Visual Basic, C#, C++] and

[Visual Basic, C#, C++] <?xml version="1.0"><!DOCTYPE price SYSTEM


[Visual Basic, C#, C++] and

[Visual Basic, C#, C++] <?xml version="1.0"><!DOCTYPE price SYSTEM "abc"



[Visual Basic, C#, C++] and

[Visual Basic, C#, C++] <!-- some test comment --><?processing


[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

XmlReader Class | XmlReader Members | System.Xml Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.