Edit

Share via


XmlReader.ReadToNextSibling Method

Definition

Advances the XmlReader to the next matching sibling element.

Overloads

ReadToNextSibling(String)

Advances the XmlReader to the next sibling element with the specified qualified name.

ReadToNextSibling(String, String)

Advances the XmlReader to the next sibling element with the specified local name and namespace URI.

ReadToNextSibling(String)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

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

Parameters

name
String

The qualified name of the sibling element you wish to move to.

Returns

true if a matching sibling element is found; otherwise false. If a matching sibling element is not found, the XmlReader is positioned on the end tag (NodeType is XmlNodeType.EndElement) of the parent element.

Exceptions

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

The parameter is an empty string.

Examples

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

Remarks

Note

Do not call ReadToNextSibling when the XmlReader is an initial state (ReadState is Initial). You can call Read to advance the XmlReader and then call the ReadToNextSibling method.

Applies to

ReadToNextSibling(String, String)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

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

Parameters

localName
String

The local name of the sibling element you wish to move to.

namespaceURI
String

The namespace URI of the sibling element you wish to move to.

Returns

true if a matching sibling element is found; otherwise, false. If a matching sibling element is not found, the XmlReader is positioned on the end tag (NodeType is XmlNodeType.EndElement) of the parent element.

Exceptions

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

Both parameter values are null.

Remarks

Note

Do not call ReadToNextSibling when the XmlReader is an initial state (ReadState is Initial). You can call Read to advance the XmlReader and then call the ReadToNextSibling method.

Applies to