Export (0) Print
Expand All

XmlLinkedNode.PreviousSibling Property

Gets the node immediately preceding this node.

[Visual Basic]
Overrides Public ReadOnly Property PreviousSibling As XmlNode
[C#]
public override XmlNode PreviousSibling {get;}
[C++]
public: __property XmlNode* get_PreviousSibling();
[JScript]
public override function get PreviousSibling() : XmlNode;

Property Value

The preceding XmlNode or a null reference (Nothing in Visual Basic) if one does not exist.

Example

The following example displays the last two books.

[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 lastNode as XmlNode = doc.DocumentElement.LastChild
      Console.WriteLine("Last book...")
      Console.WriteLine(lastNode.OuterXml)

      Dim prevNode as XmlNode = lastNode.PreviousSibling
      Console.WriteLine(ControlChars.LF + "Previous book...")
      Console.WriteLine(prevNode.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 lastNode = doc.DocumentElement.LastChild;
      Console.WriteLine("Last book...");
      Console.WriteLine(lastNode.OuterXml);

      XmlNode prevNode = lastNode.PreviousSibling;
      Console.WriteLine("\r\nPrevious book...");
      Console.WriteLine(prevNode.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* lastNode = doc->DocumentElement->LastChild;
       Console::WriteLine(S"Last book...");
       Console::WriteLine(lastNode->OuterXml);

       XmlNode* prevNode = lastNode->PreviousSibling;
       Console::WriteLine(S"\r\nPrevious book...");
       Console::WriteLine(prevNode->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

XmlLinkedNode Class | XmlLinkedNode Members | System.Xml Namespace | NextSibling

Show:
© 2014 Microsoft