Share via


XMLNode.PreviousSibling Property

Gets a XMLNode object that represents the previous XMLNode object in the document that is at the same level as the Microsoft.Office.Tools.Word.XMLNode control.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
ReadOnly Property PreviousSibling As XMLNode
XMLNode PreviousSibling { get; }

Property Value

Type: XMLNode
A XMLNode object that represents the previous XMLNode object in the document that is at the same level as the Microsoft.Office.Tools.Word.XMLNode control.

Remarks

If the current XMLNode is the first element in the XMLNodes collection, this property returns nulla null reference (Nothing in Visual Basic).

Examples

The following code example uses the PreviousSibling and NextSibling properties to display the names of the elements before and after an XMLNode control. This example assumes that the current document contains an XMLNode named CustomerFirstNameNode.

Private Sub DisplaySiblings()

    ' Display the previous sibling, if one exists. 
    If Not (Me.CustomerFirstNameNode.PreviousSibling Is Nothing) Then
        MsgBox("The previous sibling of '" & _
            Me.CustomerFirstNameNode.BaseName & "' is  '" & _
            Me.CustomerFirstNameNode.PreviousSibling.BaseName & "'.")
    Else
        MsgBox("'" & Me.CustomerFirstNameNode.BaseName & _
            "' is the first node in its hierarchy.")
    End If 

    ' Display the next sibling, if one exists. 
    If Not (Me.CustomerFirstNameNode.NextSibling Is Nothing) Then

        MsgBox("The next sibling of '" & _
            Me.CustomerFirstNameNode.BaseName & "' is '" & _
            Me.CustomerFirstNameNode.NextSibling.BaseName & "'.")
    Else
        MsgBox("'" & Me.CustomerFirstNameNode.BaseName & _
            "' is the last node in its hierarchy.")
    End If 
End Sub
private void DisplaySiblings()
{
    // Display the previous sibling, if one exists. 
    if (this.CustomerFirstNameNode.PreviousSibling != null)
    {
        MessageBox.Show("The previous sibling of '" +
            this.CustomerFirstNameNode.BaseName + "' is  '" +
            this.CustomerFirstNameNode.PreviousSibling.BaseName +
            "'.");
    }
    else
    {
        MessageBox.Show("'" + this.CustomerFirstNameNode.BaseName +
            "' is the first node in its hierarchy.");
    }

    // Display the next sibling, if one exists. 
    if (this.CustomerFirstNameNode.NextSibling != null)
    {

        MessageBox.Show("The next sibling of '" +
            this.CustomerFirstNameNode.BaseName + "' is '" +
            this.CustomerFirstNameNode.NextSibling.BaseName +
            "'.");
    }
    else
    {
        MessageBox.Show("'" + this.CustomerFirstNameNode.BaseName +
            "' is the last node in its hierarchy.");
    }
}

.NET Framework Security

See Also

Reference

XMLNode Interface

Microsoft.Office.Tools.Word Namespace