XmlReader.ReadToNextSibling XmlReader.ReadToNextSibling XmlReader.ReadToNextSibling XmlReader.ReadToNextSibling Method

定义

XmlReader 前进到下一个匹配的同级元素。Advances the XmlReader to the next matching sibling element.

重载

ReadToNextSibling(String) ReadToNextSibling(String) ReadToNextSibling(String) ReadToNextSibling(String)

XmlReader 前进到下一个具有指定限定名的同级元素。Advances the XmlReader to the next sibling element with the specified qualified name.

ReadToNextSibling(String, String) ReadToNextSibling(String, String) ReadToNextSibling(String, String) ReadToNextSibling(String, String)

XmlReader 推进到具有指定的本地名称和命名空间 URI 的下一个同级元素。Advances the XmlReader to the next sibling element with the specified local name and namespace URI.

ReadToNextSibling(String) ReadToNextSibling(String) ReadToNextSibling(String) ReadToNextSibling(String)

XmlReader 前进到下一个具有指定限定名的同级元素。Advances the XmlReader to the next sibling element with the specified qualified name.

public:
 virtual bool ReadToNextSibling(System::String ^ name);
public virtual bool ReadToNextSibling (string name);
abstract member ReadToNextSibling : string -> bool
override this.ReadToNextSibling : string -> bool
Public Overridable Function ReadToNextSibling (name As String) As Boolean

参数

name
String String String String

要移动到的同级元素的限定名。The qualified name of the sibling element you wish to move to.

返回

如果找到匹配的同级元素,则为 true;否则为 falsetrue if a matching sibling element is found; otherwise false. 如果没有找到匹配的同级元素,XmlReader 会定位在父元素的结束标记(NodeTypeXmlNodeType.EndElement)上。If a matching sibling element is not found, the XmlReader is positioned on the end tag (NodeType is XmlNodeType.EndElement) of the parent element.

异常

在上一次异步操作完成之前调用了 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."

参数是空字符串。The parameter is an empty string.

示例

下面的示例读取每个 book 节点上的 ISBN 特性。The following example reads the ISBN attribute on each book node.

using (XmlReader reader = XmlReader.Create("books.xml")) {
    reader.ReadToFollowing("book");
    do {
       Console.WriteLine("ISBN: {0}", reader.GetAttribute("ISBN")); 
    } while (reader.ReadToNextSibling("book"));
}
Using reader As XmlReader = XmlReader.Create("books.xml")
  reader.ReadToFollowing("book")
  Do
    Console.WriteLine("ISBN: {0}", reader.GetAttribute("ISBN"))
  Loop While reader.ReadToNextSibling("book")
End Using

注解

备注

当是初始ReadToNextSibling状态ReadState (为Initial)时不调用。 XmlReaderDo not call ReadToNextSibling when the XmlReader is an initial state (ReadState is Initial). 您可以调用ReadXmlReader前进,然后调用ReadToNextSibling方法。You can call Read to advance the XmlReader and then call the ReadToNextSibling method.

ReadToNextSibling(String, String) ReadToNextSibling(String, String) ReadToNextSibling(String, String) ReadToNextSibling(String, String)

XmlReader 推进到具有指定的本地名称和命名空间 URI 的下一个同级元素。Advances the XmlReader to the next sibling element with the specified local name and namespace URI.

public:
 virtual bool ReadToNextSibling(System::String ^ localName, System::String ^ namespaceURI);
public virtual bool ReadToNextSibling (string localName, string namespaceURI);
abstract member ReadToNextSibling : string * string -> bool
override this.ReadToNextSibling : string * string -> bool
Public Overridable Function ReadToNextSibling (localName As String, namespaceURI As String) As Boolean

参数

localName
String String String String

要移动到的同级元素的本地名称。The local name of the sibling element you wish to move to.

namespaceURI
String String String String

你希望移动到的同级元素的命名空间 URI。The namespace URI of the sibling element you wish to move to.

返回

如果找到匹配的同级元素,则为 true;否则为 falsetrue if a matching sibling element is found; otherwise, false. 如果没有找到匹配的同级元素,XmlReader 会定位在父元素的结束标记(NodeTypeXmlNodeType.EndElement)上。If a matching sibling element is not found, the XmlReader is positioned on the end tag (NodeType is XmlNodeType.EndElement) of the parent element.

异常

在上一次异步操作完成之前调用了 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."

两个参数值均为 nullBoth parameter values are null.

注解

备注

当是初始ReadToNextSibling状态ReadState (为Initial)时不调用。 XmlReaderDo not call ReadToNextSibling when the XmlReader is an initial state (ReadState is Initial). 您可以调用ReadXmlReader前进,然后调用ReadToNextSibling方法。You can call Read to advance the XmlReader and then call the ReadToNextSibling method.

适用于