docx
    Preparing search index...

    Class IgnoreIfEmptyXmlComponentAbstract

    XML component that is excluded from output if it has no meaningful content.

    IgnoreIfEmptyXmlComponent is useful for optional container elements that should only appear in the XML if they contain children or attributes. If the element would be empty, it returns undefined instead, causing it to be excluded from the output.

    class OptionalContainer extends IgnoreIfEmptyXmlComponent {
    constructor(items?: Item[]) {
    super("w:container");
    if (items) {
    items.forEach(item => this.root.push(item));
    }
    }
    }

    const container1 = new OptionalContainer([item1, item2]);
    // Renders: <w:container>...</w:container>

    const container2 = new OptionalContainer();
    // Renders: nothing (excluded from output)

    Hierarchy (View Summary)

    Index
    • get writtenAs(): readonly BaseXmlComponent[] | undefined
      Internal

      The components written in this one's place, one after another, when it can't be written as a single element, such as a run with another run in its children. Undefined when it is written as itself.

      Returns readonly BaseXmlComponent[] | undefined