NodePreviousSibling Property

Gets the node immediately preceding this node.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.10.0

ExpandedSyntax

public Node PreviousSibling { get; }

Property Value

Type: Node

ExpandedRemarks

If there is no preceding node, a null is returned.

ExpandedExamples

Shows how to use of methods of Node and CompositeNode to remove a section before the last section in the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create a second section by inserting a section break and add text to both sections
builder.Writeln("Section 1 text.");
builder.InsertBreak(BreakType.SectionBreakContinuous);
builder.Writeln("Section 2 text.");

// Both sections are siblings of each other
Section lastSection = (Section)doc.LastChild;
Section firstSection = (Section)lastSection.PreviousSibling;

// Remove a section based on its sibling relationship with another section
if (lastSection.PreviousSibling != null)
    doc.RemoveChild(firstSection);

// The section we removed was the first one, leaving the document with only the second
Assert.AreEqual("Section 2 text.", doc.GetText().Trim());

ExpandedSee Also