CompositeNode.RemoveChild method

Removes the specified child node.

public Node RemoveChild(Node oldChild)
Parameter Type Description
oldChild Node The node to remove.

Return Value

The removed node.


The parent of oldChild is set to null after the node is removed.


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

builder.Writeln("Section 1 text.");
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)

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

See Also