Skip to main content

Class: XmlHelper

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

Constructors

Constructor

new XmlHelper(): XmlHelper

Returns

XmlHelper

Methods

append()

static append(element): Promise<Element>

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

Parameters

element

HelperElement

Returns

Promise<Element>


appendClone()

static appendClone(childToClone, parent): Element

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

Parameters

childToClone

Element

parent

Element

Returns

Element


appendIf()

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

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

Parameters

element

HelperElement

Returns

Promise<boolean | Element>


appendImageExtensionToContentType()

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

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

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:575

Parameters

sharedStrings

Document

stringValue

string

Returns

number


collectionToArray()

static collectionToArray(collection): Element[]

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

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:524

Parameters

archive

IArchive

attributes

DefaultAttribute | OverrideAttribute

Returns

HelperElement


createRelationshipChild()

static createRelationshipChild(archive, targetRelFile, attributes): HelperElement

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

Parameters

archive

IArchive

targetRelFile

string

attributes

RelationshipAttribute

Returns

HelperElement


dump()

static dump(element): void

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

Parameters

element

Node | Document | Element

Returns

void


findByAttribute()

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

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

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:506

Parameters

nodes

XmlElementCollection | XmlNodeCollection

attributeName

string

attributeValue

string

Returns

Element[]


findByCreationId()

static findByCreationId(doc, creationId): Element

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

Parameters

doc

Document

creationId

string

Returns

Element


findByElementCreationId()

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

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

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:441

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:452

Parameters

doc

Document

name

string

nameIdx?

number

Returns

Element


findElement()

static findElement(element, tagName): Element

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

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:489

Parameters

nodes

XmlElementCollection | XmlNodeCollection

attributeName

string

attributeValue

string

Returns

Element


getClosestParent()

static getClosestParent(tag, element): Element

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

Parameters

tag

string

element

Element

Returns

Element


getFirstDirectChild()

static getFirstDirectChild(element, tagNames): Element

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

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:140

Parameters

rels

XmlElementCollection | XmlNodeCollection

attribute

string

increment?

boolean

minId?

number

Returns

number


getNextRelId()

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

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

Parameters

rootArchive

IArchive

file

string

Returns

Promise<string>


getRelationshipItems()

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

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

Parameters

archive

IArchive

path

string

cb

GetRelationshipsCallback

tag?

string

Returns

Promise<Target[]>


getRelationshipTargetsByPrefix()

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

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

Parameters

archive

IArchive

path

string

prefix

string | string[]

Returns

Promise<Target[]>


getTargetByRelId()

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

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

Parameters

archive

IArchive

relsPath

string

element

Element

type

string

Returns

Promise<Target>


getTargetsByRelationshipType()

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

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

Parameters

archive

IArchive

path

string

type

string

Returns

Promise<Target[]>


getXmlFromArchive()

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

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

Parameters

archive

IArchive

file

string

Returns

Promise<Document>


insertAfter()

static insertAfter(newNode, referenceNode): Element

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

Parameters

newNode

Element

referenceNode

Element

Returns

Element


insertInSchemaOrder()

static insertInSchemaOrder(parent, child, order): Element

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

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:427

Parameters

selector

string

Returns

boolean


modifyCollection()

static modifyCollection(collection, callback): void

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

Parameters

collection

XmlElementCollection

callback

ModifyXmlCallback

Returns

void


modifyCollectionAsync()

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

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

Parameters

collection

XmlElementCollection

callback

ModifyXmlCallback

Returns

Promise<void>


modifyXmlInArchive()

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

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

Parameters

archive

IArchive

file

string

callbacks

ModifyXmlCallback[]

Returns

Promise<void>


moveChild()

static moveChild(childToMove, insertBefore?): void

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

Parameters

childToMove

Element

insertBefore?

Element

Returns

void


parseRelationTarget()

static parseRelationTarget(element, prefix?): Target

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

Parameters

element

Element

prefix?

string

Returns

Target


remove()

static remove(toRemove): void

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

Parameters

toRemove

Element

Returns

void


removeAllChildren()

static removeAllChildren(element): void

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

Parameters

element

Element

Returns

void


removeByTagName()

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

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

Parameters

element

Element

tagName

string

i?

number = 0

Returns

void


removeIf()

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

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

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:328

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:613

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:599

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:644

Parameters

collection

XmlElementCollection

length

number

from?

number

Returns

void


sortChildrenBySchema()

static sortChildrenBySchema(parent, order): void

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

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:797

Parameters

collection

XmlElementCollection

order

number[]

callback?

ModifyXmlCallback

Returns

void


targetMatchesRelationship()

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

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

Parameters

relType

string

subtype

string

file

string

prefix

string

Returns

boolean


writeXmlToArchive()

static writeXmlToArchive(archive, file, xml): void

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

Parameters

archive

IArchive

file

string

xml

Document

Returns

void