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.

C#
public virtual bool ReadToNextSibling(string name);

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.

C#
using (XmlReader reader = XmlReader.Create("books.xml")) {
    reader.ReadToFollowing("book");
    do {
       Console.WriteLine("ISBN: {0}", reader.GetAttribute("ISBN"));
    } while (reader.ReadToNextSibling("book"));
}

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

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

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.

C#
public virtual bool ReadToNextSibling(string localName, string namespaceURI);

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

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0