Google Apps Script API
    Preparing search index...

    A representation of an XML Element node.

    // Adds up the values listed in a sample XML document and adds a new element with the total.
    var xml = '<things>'
        + '<plates>12</plates>'
        + '<bowls>18</bowls>'
        + '<cups>25</cups>'
        + '</things>';
    var document = XmlService.parse(xml);
    var root = document.getRootElement();
    var items = root.getChildren();
    var total = 0;
    for (var i = 0; i < items.length; i++) {
      total += Number(items[i].getText());
    }
    var totalElement = XmlService.createElement('total').setText(total);
    root.addContent(totalElement);
    xml = XmlService.getPrettyFormat().format(document);
    Logger.log(xml);
    
    interface Element {
        addContent(
            content: GoogleAppsScript.XML_Service.Content,
        ): GoogleAppsScript.XML_Service.Element;
        addContent(
            index: number,
            content: GoogleAppsScript.XML_Service.Content,
        ): GoogleAppsScript.XML_Service.Element;
        asCdata(): Cdata;
        asComment(): GoogleAppsScript.XML_Service.Comment;
        asDocType(): DocType;
        asElement(): GoogleAppsScript.XML_Service.Element;
        asEntityRef(): EntityRef;
        asProcessingInstruction(): ProcessingInstruction;
        asText(): GoogleAppsScript.XML_Service.Text;
        cloneContent(): GoogleAppsScript.XML_Service.Content[];
        detach(): GoogleAppsScript.XML_Service.Content;
        getAllContent(): GoogleAppsScript.XML_Service.Content[];
        getAttribute(name: string): GoogleAppsScript.XML_Service.Attribute;
        getAttribute(
            name: string,
            namespace: Namespace,
        ): GoogleAppsScript.XML_Service.Attribute;
        getAttributes(): GoogleAppsScript.XML_Service.Attribute[];
        getChild(name: string): GoogleAppsScript.XML_Service.Element;
        getChild(
            name: string,
            namespace: Namespace,
        ): GoogleAppsScript.XML_Service.Element;
        getChildren(): GoogleAppsScript.XML_Service.Element[];
        getChildren(name: string): GoogleAppsScript.XML_Service.Element[];
        getChildren(
            name: string,
            namespace: Namespace,
        ): GoogleAppsScript.XML_Service.Element[];
        getChildText(name: string): string;
        getChildText(name: string, namespace: Namespace): string;
        getContent(index: number): GoogleAppsScript.XML_Service.Content;
        getContentSize(): number;
        getDescendants(): GoogleAppsScript.XML_Service.Content[];
        getDocument(): GoogleAppsScript.XML_Service.Document;
        getName(): string;
        getNamespace(): Namespace;
        getNamespace(prefix: string): Namespace;
        getParentElement(): GoogleAppsScript.XML_Service.Element;
        getQualifiedName(): string;
        getText(): string;
        getType(): GoogleAppsScript.XML_Service.ContentType;
        getValue(): string;
        isAncestorOf(other: GoogleAppsScript.XML_Service.Element): boolean;
        isRootElement(): boolean;
        removeAttribute(attribute: GoogleAppsScript.XML_Service.Attribute): boolean;
        removeAttribute(attributeName: string): boolean;
        removeAttribute(attributeName: string, namespace: Namespace): boolean;
        removeContent(): GoogleAppsScript.XML_Service.Content[];
        removeContent(content: GoogleAppsScript.XML_Service.Content): boolean;
        removeContent(index: number): GoogleAppsScript.XML_Service.Content;
        setAttribute(
            attribute: GoogleAppsScript.XML_Service.Attribute,
        ): GoogleAppsScript.XML_Service.Element;
        setAttribute(
            name: string,
            value: string,
        ): GoogleAppsScript.XML_Service.Element;
        setAttribute(
            name: string,
            value: string,
            namespace: Namespace,
        ): GoogleAppsScript.XML_Service.Element;
        setName(name: string): GoogleAppsScript.XML_Service.Element;
        setNamespace(namespace: Namespace): GoogleAppsScript.XML_Service.Element;
        setText(text: string): GoogleAppsScript.XML_Service.Element;
    }

    Hierarchy (View Summary)

    Index

    Methods