Skip to main content

Class: XmlHelper

Defined in: src/helper/xml-helper.ts:23

Constructors​

Constructor​

new XmlHelper(): XmlHelper

Returns​

XmlHelper

Methods​

append()​

static append(element): Promise<Element>

Defined in: src/helper/xml-helper.ts:66

Parameters​

element​

HelperElement

Returns​

Promise<Element>


appendClone()​

static appendClone(childToClone, parent): Element

Defined in: src/helper/xml-helper.ts:627

Parameters​

childToClone​

Element

parent​

Element

Returns​

Element


appendIf()​

static appendIf(element): Promise<boolean | Element>

Defined in: src/helper/xml-helper.ts:55

Parameters​

element​

HelperElement

Returns​

Promise<boolean | Element>


appendImageExtensionToContentType()​

static appendImageExtensionToContentType(targetArchive, extension): Promise<boolean | Element>

Defined in: src/helper/xml-helper.ts:392

Parameters​

targetArchive​

IArchive

extension​

"xml" | "jpg" | "jpeg" | "png" | "gif" | "svg" | "mp3" | "m4v" | "mp4" | "emf" | "wdp" | "bin" | "vml"

Returns​

Promise<boolean | Element>


appendSharedString()​

static appendSharedString(sharedStrings, stringValue): number

Defined in: src/helper/xml-helper.ts:411

Parameters​

sharedStrings​

Document

stringValue​

string

Returns​

number


collectionToArray()​

static collectionToArray(collection): Element[]

Defined in: src/helper/xml-helper.ts:469

Copies a node collection into a plain array. xmldom's LiveNodeList re-walks the entire document on .length access after a mutation, while indexed access returns entries from before it — snapshot before iterating whenever the loop (or its callback) mutates the tree.

Parameters​

collection​

XmlElementCollection | XmlNodeCollection

Returns​

Element[]


createContentTypeChild()​

static createContentTypeChild(archive, attributes): HelperElement

Defined in: src/helper/xml-helper.ts:364

Parameters​

archive​

IArchive

attributes​

DefaultAttribute | OverrideAttribute

Returns​

HelperElement


createRelationshipChild()​

static createRelationshipChild(archive, targetRelFile, attributes): HelperElement

Defined in: src/helper/xml-helper.ts:380

Parameters​

archive​

IArchive

targetRelFile​

string

attributes​

RelationshipAttribute

Returns​

HelperElement

Deprecated​

Use XmlRelationshipHelper.createRelationshipChild


dump()​

static dump(element): void

Defined in: src/helper/xml-helper.ts:676

Parameters​

element​

Node | Document | Element

Returns​

void


findByAttribute()​

static findByAttribute(xml, tagName, attributeName, attributeValue): boolean

Defined in: src/helper/xml-helper.ts:198

Parameters​

xml​

Document

tagName​

string

attributeName​

string

attributeValue​

string

Returns​

boolean


findByAttributeValue()​

static findByAttributeValue(nodes, attributeName, attributeValue): Element[]

Defined in: src/helper/xml-helper.ts:346

Parameters​

nodes​

XmlElementCollection | XmlNodeCollection

attributeName​

string

attributeValue​

string

Returns​

Element[]


findByCreationId()​

static findByCreationId(doc, creationId): Element

Defined in: src/helper/xml-helper.ts:313

Parameters​

doc​

Document

creationId​

string

Returns​

Element


findByElementCreationId()​

static findByElementCreationId(archive, path, creationId): Promise<Element>

Defined in: src/helper/xml-helper.ts:271

Parameters​

archive​

IArchive

path​

string

creationId​

string

Returns​

Promise<Element>


findByElementName()​

static findByElementName(archive, path, name, nameIdx?): Promise<Element>

Defined in: src/helper/xml-helper.ts:281

Parameters​

archive​

IArchive

path​

string

name​

string

nameIdx?​

number

Returns​

Promise<Element>


findByName()​

static findByName(doc, name, nameIdx?): Element

Defined in: src/helper/xml-helper.ts:292

Parameters​

doc​

Document

name​

string

nameIdx?​

number

Returns​

Element


findElement()​

static findElement(element, tagName): Element

Defined in: src/helper/xml-helper.ts:694

Find an element with the given tag name, searching deeply through the structure

Parameters​

element​

Element

The root element to search in

tagName​

string

The tag name to search for

Returns​

Element

The found element or null


findFirstByAttributeValue()​

static findFirstByAttributeValue(nodes, attributeName, attributeValue): Element

Defined in: src/helper/xml-helper.ts:329

Parameters​

nodes​

XmlElementCollection | XmlNodeCollection

attributeName​

string

attributeValue​

string

Returns​

Element


getClosestParent()​

static getClosestParent(tag, element): Element

Defined in: src/helper/xml-helper.ts:599

Parameters​

tag​

string

element​

Element

Returns​

Element


getFirstDirectChild()​

static getFirstDirectChild(element, tagNames): Element

Defined in: src/helper/xml-helper.ts:501

Find the first direct child of an element matching one of the given tag names. Unlike getElementsByTagName, this will not descend into grandchildren - e.g. an <a:ln> inside <p:spPr> is the shape outline, while an <a:ln> found anywhere below <p:sp> might belong to a text run.

Parameters​

element​

Element

The parent element to scan

tagNames​

string[]

Tag names to look for, in no particular order

Returns​

Element

The first matching child element, or undefined


getMaxId()​

static getMaxId(rels, attribute, increment?, minId?): number

Defined in: src/helper/xml-helper.ts:133

Parameters​

rels​

XmlElementCollection | XmlNodeCollection

attribute​

string

increment?​

boolean

minId?​

number

Returns​

number

Deprecated​

Use XmlRelationshipHelper.getMaxId


getNextRelId()​

static getNextRelId(rootArchive, file): Promise<string>

Defined in: src/helper/xml-helper.ts:125

Parameters​

rootArchive​

IArchive

file​

string

Returns​

Promise<string>

Deprecated​

Use XmlRelationshipHelper.getNextRelId


getRelationshipItems()​

static getRelationshipItems(archive, path, cb, tag?): Promise<Target[]>

Defined in: src/helper/xml-helper.ts:189

Parameters​

archive​

IArchive

path​

string

cb​

GetRelationshipsCallback

tag?​

string

Returns​

Promise<Target[]>

Deprecated​

Use XmlRelationshipHelper.getRelationshipItems


getRelationshipTargetsByPrefix()​

static getRelationshipTargetsByPrefix(archive, path, prefix): Promise<Target[]>

Defined in: src/helper/xml-helper.ts:143

Parameters​

archive​

IArchive

path​

string

prefix​

string | string[]

Returns​

Promise<Target[]>

Deprecated​

Use XmlRelationshipHelper.getRelationshipTargetsByPrefix


getTargetByRelId()​

static getTargetByRelId(archive, relsPath, element, type): Promise<Target>

Defined in: src/helper/xml-helper.ts:251

Parameters​

archive​

IArchive

relsPath​

string

element​

Element

type​

string

Returns​

Promise<Target>

Deprecated​

Use XmlRelationshipHelper.resolveElementTarget


getTargetsByRelationshipType()​

static getTargetsByRelationshipType(archive, path, type): Promise<Target[]>

Defined in: src/helper/xml-helper.ts:176

Parameters​

archive​

IArchive

path​

string

type​

string

Returns​

Promise<Target[]>

Deprecated​

Use XmlRelationshipHelper.getTargetsByRelationshipType


getXmlFromArchive()​

static getXmlFromArchive(archive, file): Promise<Document>

Defined in: src/helper/xml-helper.ts:40

Parameters​

archive​

IArchive

file​

string

Returns​

Promise<Document>


insertAfter()​

static insertAfter(newNode, referenceNode): Element

Defined in: src/helper/xml-helper.ts:453

Parameters​

newNode​

Element

referenceNode​

Element

Returns​

Element


insertInSchemaOrder()​

static insertInSchemaOrder(parent, child, order): Element

Defined in: src/helper/xml-helper.ts:528

Insert a child element at the position required by an OOXML schema sequence. Most DrawingML property containers (a:pPr, a:rPr, a:ln, …) declare their children as an ordered <xsd:sequence>: appending in call order instead of schema order is what makes PowerPoint offer to repair the file.

The new child is inserted before the first existing direct child that ranks after it in order. Tags missing from order are treated as "ranks last" and therefore never displace a known tag.

Parameters​

parent​

Element

The property container

child​

Element

The element to insert

order​

string[]

Tag names in schema sequence order

Returns​

Element


isElementCreationId()​

static isElementCreationId(selector): boolean

Defined in: src/helper/xml-helper.ts:267

Parameters​

selector​

string

Returns​

boolean


modifyCollection()​

static modifyCollection(collection, callback): void

Defined in: src/helper/xml-helper.ts:656

Parameters​

collection​

XmlElementCollection

callback​

ModifyXmlCallback

Returns​

void


modifyCollectionAsync()​

static modifyCollectionAsync(collection, callback): Promise<void>

Defined in: src/helper/xml-helper.ts:666

Parameters​

collection​

XmlElementCollection

callback​

ModifyXmlCallback

Returns​

Promise<void>


modifyXmlInArchive()​

static modifyXmlInArchive(archive, file, callbacks): Promise<void>

Defined in: src/helper/xml-helper.ts:24

Parameters​

archive​

IArchive

file​

string

callbacks​

ModifyXmlCallback[]

Returns​

Promise<void>


moveChild()​

static moveChild(childToMove, insertBefore?): void

Defined in: src/helper/xml-helper.ts:622

Parameters​

childToMove​

Element

insertBefore?​

Element

Returns​

void


parseRelationTarget()​

static parseRelationTarget(element, prefix?): Target

Defined in: src/helper/xml-helper.ts:156

Parameters​

element​

Element

prefix?​

string

Returns​

Target

Deprecated​

Use XmlRelationshipHelper.parseRelationTarget


remove()​

static remove(toRemove): void

Defined in: src/helper/xml-helper.ts:608

Parameters​

toRemove​

Element

Returns​

void


removeAllChildren()​

static removeAllChildren(element): void

Defined in: src/helper/xml-helper.ts:614

Parameters​

element​

Element

Returns​

void


removeByTagName()​

static removeByTagName(element, tagName, i?): void

Defined in: src/helper/xml-helper.ts:683

Parameters​

element​

Element

tagName​

string

i?​

number = 0

Returns​

void


removeIf()​

static removeIf(element): Promise<Element[]>

Defined in: src/helper/xml-helper.ts:101

Parameters​

element​

HelperElement

Returns​

Promise<Element[]>


replaceAttribute()​

static replaceAttribute(archive, path, tagName, attributeName, attributeValue, replaceValue, replaceAttributeName?): Promise<void>

Defined in: src/helper/xml-helper.ts:216

Parameters​

archive​

IArchive

path​

string

tagName​

string

attributeName​

string

attributeValue​

string

replaceValue​

string

replaceAttributeName?​

string

Returns​

Promise<void>


sanitizeAttr()​

static sanitizeAttr(value): string

Defined in: src/helper/xml-helper.ts:449

Sanitize attribute values for XML 1.0. Uses same rules as sanitizeText.

Parameters​

value​

string | number

Returns​

string


sanitizeText()​

static sanitizeText(value): string

Defined in: src/helper/xml-helper.ts:435

Sanitize text for XML 1.0 compatibility.

  • Replace vertical tab (\u000B / \v) with a newline.
  • Remove other disallowed control characters (except TAB, LF, CR).

Parameters​

value​

string | number

Returns​

string


sliceCollection()​

static sliceCollection(collection, length, from?): void

Defined in: src/helper/xml-helper.ts:480

Parameters​

collection​

XmlElementCollection

length​

number

from?​

number

Returns​

void


sortChildrenBySchema()​

static sortChildrenBySchema(parent, order): void

Defined in: src/helper/xml-helper.ts:566

Reorder the direct element children of a property container into the OOXML schema sequence given by order, keeping the relative order of equally-ranked and unknown tags (stable).

Useful when several independent helpers append to the same container and no single one of them can know the final child set - e.g. a:rPr, which collects a fill, a highlight, a typeface and a hyperlink from four different code paths.

Parameters​

parent​

Element

The property container

order​

string[]

Tag names in schema sequence order

Returns​

void


sortCollection()​

static sortCollection(collection, order, callback?): void

Defined in: src/helper/xml-helper.ts:633

Parameters​

collection​

XmlElementCollection

order​

number[]

callback?​

ModifyXmlCallback

Returns​

void


targetMatchesRelationship()​

static targetMatchesRelationship(relType, subtype, file, prefix): boolean

Defined in: src/helper/xml-helper.ts:161

Parameters​

relType​

string

subtype​

string

file​

string

prefix​

string

Returns​

boolean

Deprecated​

Use XmlRelationshipHelper.targetMatchesRelationship


writeXmlToArchive()​

static writeXmlToArchive(archive, file, xml): void

Defined in: src/helper/xml-helper.ts:47

Parameters​

archive​

IArchive

file​

string

xml​

Document

Returns​

void