Search Results for

    Show / Hide Table of Contents

    Class ParentElement

    Represents the base class for content elements which have children.

    Inheritance
    System.Object
    ContentElement
    ParentElement
    TableElement
    TextContainer
    Container
    DocumentSection
    ListItem
    MultiLevelTextList
    Paragraph
    Run
    Implements
    IronSoftware.Abstractions.Word.IWordDocumentObject
    IronSoftware.Abstractions.IDocumentObject
    System.ICloneable
    IronSoftware.Abstractions.IParent<IronSoftware.Abstractions.Word.IWordDocumentObjectCollection, IronSoftware.Abstractions.Word.IWordDocumentObject>
    Inherited Members
    ContentElement.Replace(IWordDocumentObject)
    ContentElement.GetIndex<T>()
    ContentElement.Parent
    ContentElement.Status
    Namespace: IronWord.Models.Abstract
    Assembly: IronWord.dll
    Syntax
    public abstract class ParentElement : ContentElement

    Holding and arranging child content in a Word document in C# is what ParentElement provides. It is the base for every node that contains other nodes, so a Paragraph holding runs, a DocumentSection holding paragraphs, a ListItem, and a Container all draw their child-management behavior from one place. Where the plain ContentElement base gives a node its identity, ParentElement adds the ability to own a subtree.

    Concrete and intermediate types that extend it include Paragraph, Run, Container, DocumentSection, ListItem, MultiLevelTextList, and the table-side bases TableElement and TableElements. A developer obtains one of these by building a document or by reading nodes out of an existing one, then works through the inherited surface to read and reshape its children. Because the behavior lives on this base, the same operations apply no matter which parent you hold.

    The member surface groups into clear functions. **Reading children:** Children returns the full child collection, while Tables and Texts give typed lists of the Table and TextContent nodes inside. **Mutating children:** AddChild appends nodes, InsertChildToIndex places one at a position, and RemoveChildren, RemoveAllChildren, and Remove detach them. **Locating and copying:** GetChildByIndex<T> fetches a typed child by position, ExtractElements<T> collects every descendant of a type, and Clone deep-copies the element. **Diagnostics:** LogObjectTree prints the subtree as readable text, which is useful when verifying the structure of a node during development before you save.

    using IronWord;
    using IronWord.Models;
    
    WordDocument doc = new WordDocument("input.docx");
    Paragraph paragraph = doc.Paragraphs[0];
    paragraph.AddChild(new Text("appended"));
    Console.WriteLine(paragraph.LogObjectTree());

    The add text how-to appends child content, the add table how-to builds nested structures, and the document element tutorial explains the parent-child tree.

    Constructors

    ParentElement()

    Initializes a new instance of the ContentElement class.

    Declaration
    protected ParentElement()

    ParentElement(IWordDocumentObject[])

    Initializes a new instance of the ContentElement class with the specified child elements.

    Declaration
    public ParentElement(params IWordDocumentObject[] children)
    Parameters
    Type Name Description
    IronSoftware.Abstractions.Word.IWordDocumentObject[] children

    The child elements to be added.

    Properties

    Children

    Gets the list of child elements contained within this element.

    Declaration
    public IWordDocumentObjectCollection Children { get; }
    Property Value
    Type Description
    IronSoftware.Abstractions.Word.IWordDocumentObjectCollection

    Tables

    A list of all table elements contained within this element or its children

    See also: ExtractElements<T>()

    Declaration
    public List<Table> Tables { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<Table>

    Texts

    A list of all text elements contained within this element or its children

    See also: ExtractElements<T>()

    Declaration
    public List<TextContent> Texts { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<TextContent>

    Methods

    AddChild(IWordDocumentObject[])

    Adds the specified child elements to this element.

    Declaration
    public virtual void AddChild(params IWordDocumentObject[] children)
    Parameters
    Type Name Description
    IronSoftware.Abstractions.Word.IWordDocumentObject[] children

    The child elements to be added.

    Clone()

    Creates a deep copy of the Element.

    Declaration
    public override object Clone()
    Returns
    Type Description
    System.Object

    A new instance of the Image with all properties copied.

    Overrides
    ContentElement.Clone()

    CloneObject()

    Declaration
    protected override object CloneObject()
    Returns
    Type Description
    System.Object
    Overrides
    ContentElement.CloneObject()

    ExtractElements<T>()

    Extracts all child elements of a specific type from this element.

    Declaration
    public List<T> ExtractElements<T>()
        where T : IWordDocumentObject
    Returns
    Type Description
    System.Collections.Generic.List<T>

    A list of child elements of the specified type.

    Type Parameters
    Name Description
    T

    The type of child element to extract.

    GetChildByIndex<T>(Int32)

    Gets the child element at the specified index, cast to the specified type.

    Declaration
    public IWordDocumentObject GetChildByIndex<T>(int index)
        where T : IWordDocumentObject
    Parameters
    Type Name Description
    System.Int32 index

    The index of the child element.

    Returns
    Type Description
    IronSoftware.Abstractions.Word.IWordDocumentObject

    The child element at the specified index.

    Type Parameters
    Name Description
    T

    The type of the child element to retrieve.

    InsertChildToIndex(Int32, IWordDocumentObject[])

    Inserts the specified child elements at the specified index.

    Declaration
    public void InsertChildToIndex(int index, params IWordDocumentObject[] children)
    Parameters
    Type Name Description
    System.Int32 index

    The index at which to insert the children.

    IronSoftware.Abstractions.Word.IWordDocumentObject[] children

    The child elements to be inserted.

    LogObjectTree()

    Initiates logging of the object tree by traversing from the current object.

    Declaration
    public string LogObjectTree()
    Returns
    Type Description
    System.String

    Remove()

    Marks this element as deleted.

    Declaration
    public override void Remove()
    Overrides
    ContentElement.Remove()

    RemoveAllChildren()

    Removes all child elements from this element.

    Declaration
    public void RemoveAllChildren()

    RemoveChildren(IWordDocumentObject[])

    Removes the specified child elements from this element.

    Declaration
    public void RemoveChildren(params IWordDocumentObject[] children)
    Parameters
    Type Name Description
    IronSoftware.Abstractions.Word.IWordDocumentObject[] children

    The child elements to be removed.

    Implements

    IronSoftware.Abstractions.Word.IWordDocumentObject
    IronSoftware.Abstractions.IDocumentObject
    System.ICloneable
    IronSoftware.Abstractions.IParent<, >

    Inherited members

    Replace(IWordDocumentObject)
    GetIndex<T>()
    Parent
    Status
    ☀
    ☾
    Downloads
    • Download with NuGet
    • Start for Free
    In This Article
    Back to top
    Install with NuGet
    IronWord_for_dotnet_log2o
    Blue key in circleGet started for FREE
    No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet started for FREE
    The trial form was submitted successfully.
    Calendar in circleBook Free Live Demo
    No contact, no card details, no commitments Book a 30-minute, personal demo.
    Here's what to expect:

    A live demo of our product and its key features

    Get project specific feature recommendations

    All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation
    Support Team Member 6 related to The C# PDF Library Support Team Member 14 related to The C# PDF Library Support Team Member 4 related to The C# PDF Library Support Team Member 2 related to The C# PDF Library
    Online 24/5
    Need help? Our sales team would be glad to help you.
    Try the Enterprise Trial
    ironpdf_for_dotnet_log2o
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    bullet_checkedNo credit card or account creation required
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    Blue key in circleNo credit card or account creation required
    Green Check in orange circle
    The trial form was submitted successfully.
    badge_greencheck_in_yellowcircle
    Thank you for starting a trial

    Please check your email for the trial license key.

    If you don’t receive an email, please start a live chat or email support@ironsoftware.com

    Install with NuGet
    View Licensing
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronWord