Edit

Share via


XmlNode.NextSibling Property

Definition

Gets the node immediately following this node.

public virtual System.Xml.XmlNode NextSibling { get; }
public virtual System.Xml.XmlNode? NextSibling { get; }

Property Value

The next XmlNode. If there is no next node, null is returned.

Examples

The following example displays all the books in the XML document.

using System;
using System.Xml;

public class Sample4
{
    public static void Main()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load("books.xml");

        XmlNode currNode = doc.DocumentElement.FirstChild;
        Console.WriteLine("First book...");
        Console.WriteLine(currNode.OuterXml);

        XmlNode nextNode = currNode.NextSibling;
        Console.WriteLine("\r\nSecond book...");
        Console.WriteLine(nextNode.OuterXml);
    }
}

Applies to