XmlReader.MoveToContent Method
This page is specific to:.NET Framework Version:1.12.03.03.5Silverlight 34.0
.NET Framework Class Library
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
[C#]
public virtual XmlNodeType MoveToContent();
[C++]
public: virtual XmlNodeType MoveToContent();
[JScript]
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.

Exceptions

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

Remarks

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

Example

[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

[C#] 
if (reader.MoveToContent() == XmlNodeType.Element && reader.Name == "price") 
 {
    _price = reader.ReadString();
 }

[C++] 
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

"abc"><price>123.4</price>

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

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

[<!ENTTIY p

"123.4">]><price>&p;</price>

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

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

instruction?><price>123.4</price>

[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.

Requirements

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

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View