Class: XmlHelper
Defined in: src/helper/xml-helper.ts:24
Constructors
Constructor
new XmlHelper():
XmlHelper
Returns
XmlHelper
Methods
append()
staticappend(element):Promise<Element>
Defined in: src/helper/xml-helper.ts:67
Parameters
element
HelperElement
Returns
Promise<Element>
appendClone()
staticappendClone(childToClone,parent):Element
Defined in: src/helper/xml-helper.ts:791
Parameters
childToClone
Element
parent
Element
Returns
Element
appendIf()
staticappendIf(element):Promise<boolean|Element>
Defined in: src/helper/xml-helper.ts:56
Parameters
element
HelperElement
Returns
Promise<boolean | Element>
appendImageExtensionToContentType()
staticappendImageExtensionToContentType(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()
staticappendSharedString(sharedStrings,stringValue):number
Defined in: src/helper/xml-helper.ts:575
Parameters
sharedStrings
Document
stringValue
string
Returns
number
collectionToArray()
staticcollectionToArray(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()
staticcreateContentTypeChild(archive,attributes):HelperElement
Defined in: src/helper/xml-helper.ts:524
Parameters
archive
IArchive
attributes
DefaultAttribute | OverrideAttribute
Returns
HelperElement
createRelationshipChild()
staticcreateRelationshipChild(archive,targetRelFile,attributes):HelperElement
Defined in: src/helper/xml-helper.ts:539
Parameters
archive
IArchive
targetRelFile
string
attributes
RelationshipAttribute
Returns
HelperElement
dump()
staticdump(element):void
Defined in: src/helper/xml-helper.ts:840
Parameters
element
Node | Document | Element
Returns
void
findByAttribute()
staticfindByAttribute(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()
staticfindByAttributeValue(nodes,attributeName,attributeValue):Element[]
Defined in: src/helper/xml-helper.ts:506
Parameters
nodes
XmlElementCollection | XmlNodeCollection
attributeName
string
attributeValue
string
Returns
Element[]
findByCreationId()
staticfindByCreationId(doc,creationId):Element
Defined in: src/helper/xml-helper.ts:473
Parameters
doc
Document
creationId
string
Returns
Element
findByElementCreationId()
staticfindByElementCreationId(archive,path,creationId):Promise<Element>
Defined in: src/helper/xml-helper.ts:431
Parameters
archive
IArchive
path
string
creationId
string
Returns
Promise<Element>
findByElementName()
staticfindByElementName(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()
staticfindByName(doc,name,nameIdx?):Element
Defined in: src/helper/xml-helper.ts:452
Parameters
doc
Document
name
string
nameIdx?
number
Returns
Element
findElement()
staticfindElement(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()
staticfindFirstByAttributeValue(nodes,attributeName,attributeValue):Element
Defined in: src/helper/xml-helper.ts:489
Parameters
nodes
XmlElementCollection | XmlNodeCollection
attributeName
string
attributeValue
string
Returns
Element
getClosestParent()
staticgetClosestParent(tag,element):Element
Defined in: src/helper/xml-helper.ts:763
Parameters
tag
string
element
Element
Returns
Element
getFirstDirectChild()
staticgetFirstDirectChild(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()
staticgetMaxId(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()
staticgetNextRelId(rootArchive,file):Promise<string>
Defined in: src/helper/xml-helper.ts:125
Parameters
rootArchive
IArchive
file
string
Returns
Promise<string>
getRelationshipItems()
staticgetRelationshipItems(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()
staticgetRelationshipTargetsByPrefix(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()
staticgetTargetByRelId(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()
staticgetTargetsByRelationshipType(archive,path,type):Promise<Target[]>
Defined in: src/helper/xml-helper.ts:267
Parameters
archive
IArchive
path
string
type
string
Returns
Promise<Target[]>
getXmlFromArchive()
staticgetXmlFromArchive(archive,file):Promise<Document>
Defined in: src/helper/xml-helper.ts:41
Parameters
archive
IArchive
file
string
Returns
Promise<Document>
insertAfter()
staticinsertAfter(newNode,referenceNode):Element
Defined in: src/helper/xml-helper.ts:617
Parameters
newNode
Element
referenceNode
Element
Returns
Element
insertInSchemaOrder()
staticinsertInSchemaOrder(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()
staticisElementCreationId(selector):boolean
Defined in: src/helper/xml-helper.ts:427
Parameters
selector
string
Returns
boolean
modifyCollection()
staticmodifyCollection(collection,callback):void
Defined in: src/helper/xml-helper.ts:820
Parameters
collection
XmlElementCollection
callback
ModifyXmlCallback
Returns
void
modifyCollectionAsync()
staticmodifyCollectionAsync(collection,callback):Promise<void>
Defined in: src/helper/xml-helper.ts:830
Parameters
collection
XmlElementCollection
callback
ModifyXmlCallback
Returns
Promise<void>
modifyXmlInArchive()
staticmodifyXmlInArchive(archive,file,callbacks):Promise<void>
Defined in: src/helper/xml-helper.ts:25
Parameters
archive
IArchive
file
string
callbacks
ModifyXmlCallback[]
Returns
Promise<void>
moveChild()
staticmoveChild(childToMove,insertBefore?):void
Defined in: src/helper/xml-helper.ts:786
Parameters
childToMove
Element
insertBefore?
Element
Returns
void
parseRelationTarget()
staticparseRelationTarget(element,prefix?):Target
Defined in: src/helper/xml-helper.ts:194
Parameters
element
Element
prefix?
string
Returns
Target
remove()
staticremove(toRemove):void
Defined in: src/helper/xml-helper.ts:772
Parameters
toRemove
Element
Returns
void
removeAllChildren()
staticremoveAllChildren(element):void
Defined in: src/helper/xml-helper.ts:778
Parameters
element
Element
Returns
void
removeByTagName()
staticremoveByTagName(element,tagName,i?):void
Defined in: src/helper/xml-helper.ts:847
Parameters
element
Element
tagName
string
i?
number = 0
Returns
void
removeIf()
staticremoveIf(element):Promise<Element[]>
Defined in: src/helper/xml-helper.ts:102
Parameters
element
HelperElement
Returns
Promise<Element[]>
replaceAttribute()
staticreplaceAttribute(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()
staticsanitizeAttr(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()
staticsanitizeText(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()
staticsliceCollection(collection,length,from?):void
Defined in: src/helper/xml-helper.ts:644
Parameters
collection
XmlElementCollection
length
number
from?
number
Returns
void
sortChildrenBySchema()
staticsortChildrenBySchema(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()
staticsortCollection(collection,order,callback?):void
Defined in: src/helper/xml-helper.ts:797
Parameters
collection
XmlElementCollection
order
number[]
callback?
ModifyXmlCallback
Returns
void
targetMatchesRelationship()
statictargetMatchesRelationship(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()
staticwriteXmlToArchive(archive,file,xml):void
Defined in: src/helper/xml-helper.ts:48
Parameters
archive
IArchive
file
string
xml
Document
Returns
void