XmlReader.MoveToContent XmlReader.MoveToContent XmlReader.MoveToContent XmlReader.MoveToContent Method

定义

检查当前节点是否是内容(非空白文本、CDATAElementEndElementEntityReferenceEndEntity)节点。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. 它跳过以下类型的节点:ProcessingInstructionDocumentTypeCommentWhitespaceSignificantWhitespaceIt 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

返回

此方法找到的当前节点的 NodeType;如果读取器已到达输入流的末尾,则为 XmlNodeType.NoneThe NodeType of the current node found by the method or XmlNodeType.None if the reader has reached the end of the input stream.

异常

在输入流中遇到不正确的 XML。Incorrect XML encountered in the input stream.

在上一次异步操作完成之前调用了 XmlReader 方法。An XmlReader method was called before a previous asynchronous operation finished. 在此情况下,会引发 InvalidOperationException 并显示消息“异步操作已在进行中。”In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

示例

当你想要编写代码,可以跳过随机 XML 标记,但不会中断时,这很有用。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.

此方法的异步版本,请参阅MoveToContentAsyncFor the asynchronous version of this method, see MoveToContentAsync.

适用于