Export (0) Print
Expand All

XmlNode.NextSibling Property

Gets the node immediately following this node.

[Visual Basic]
Public Overridable ReadOnly Property NextSibling As XmlNode
[C#]
public virtual XmlNode NextSibling {get;}
[C++]
public: __property virtual XmlNode* get_NextSibling();
[JScript]
public function get NextSibling() : XmlNode;

Property Value

The next XmlNode. If there is no next node, a null reference (Nothing in Visual Basic) is returned.

Example

[Visual Basic, C#, C++] The following example displays all the books in the XML document.

[Visual Basic] 
Imports System
Imports System.Xml
Imports Microsoft.VisualBasic

public class Sample 

  public shared sub Main() 

      Dim doc as XmlDocument = new XmlDocument()
      doc.Load("books.xml")

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

      Dim nextNode as XmlNode = currNode.NextSibling
      Console.WriteLine(ControlChars.LF + "Second book...")
      Console.WriteLine(nextNode.OuterXml) 

  end sub
end class

[C#] 
using System;
using System.Xml;

public class Sample {

  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); 

  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;

int main()
{

    XmlDocument* doc = new XmlDocument();
    doc->Load(S"books.xml");
 
    XmlNode* currNode = doc->DocumentElement->FirstChild;
    Console::WriteLine(S"First book...");
    Console::WriteLine(currNode->OuterXml);

    XmlNode* nextNode = currNode->NextSibling;
    Console::WriteLine(S"\r\nSecond book...");
    Console::WriteLine(nextNode->OuterXml); 
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlNode Class | XmlNode Members | System.Xml Namespace

Show:
© 2014 Microsoft