Class: XmlHelper
Defined in: src/helper/xml-helper.ts:23
Constructors
Constructor
new XmlHelper():
XmlHelper
Returns
XmlHelper
Methods
append()
staticappend(element):Promise<Element>
Defined in: src/helper/xml-helper.ts:66
Parameters
element
HelperElement
Returns
Promise<Element>
appendClone()
staticappendClone(childToClone,parent):Element
Defined in: src/helper/xml-helper.ts:627
Parameters
childToClone
Element
parent
Element
Returns
Element
appendIf()
staticappendIf(element):Promise<boolean|Element>
Defined in: src/helper/xml-helper.ts:55
Parameters
element
HelperElement
Returns
Promise<boolean | Element>
appendImageExtensionToContentType()
staticappendImageExtensionToContentType(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()
staticappendSharedString(sharedStrings,stringValue):number
Defined in: src/helper/xml-helper.ts:411
Parameters
sharedStrings
Document
stringValue
string
Returns
number
collectionToArray()
staticcollectionToArray(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()
staticcreateContentTypeChild(archive,attributes):HelperElement
Defined in: src/helper/xml-helper.ts:364
Parameters
archive
IArchive
attributes
DefaultAttribute | OverrideAttribute
Returns
HelperElement
createRelationshipChild()
staticcreateRelationshipChild(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()
staticdump(element):void
Defined in: src/helper/xml-helper.ts:676
Parameters
element
Node | Document | Element
Returns
void
findByAttribute()
staticfindByAttribute(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()
staticfindByAttributeValue(nodes,attributeName,attributeValue):Element[]
Defined in: src/helper/xml-helper.ts:346
Parameters
nodes
XmlElementCollection | XmlNodeCollection
attributeName
string
attributeValue
string
Returns
Element[]
findByCreationId()
staticfindByCreationId(doc,creationId):Element
Defined in: src/helper/xml-helper.ts:313
Parameters
doc
Document
creationId
string
Returns
Element
findByElementCreationId()
staticfindByElementCreationId(archive,path,creationId):Promise<Element>
Defined in: src/helper/xml-helper.ts:271
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:281
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:292
Parameters
doc
Document
name
string
nameIdx?
number
Returns
Element
findElement()
staticfindElement(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()
staticfindFirstByAttributeValue(nodes,attributeName,attributeValue):Element
Defined in: src/helper/xml-helper.ts:329
Parameters
nodes
XmlElementCollection | XmlNodeCollection
attributeName
string
attributeValue
string
Returns
Element
getClosestParent()
staticgetClosestParent(tag,element):Element
Defined in: src/helper/xml-helper.ts:599
Parameters
tag
string
element
Element
Returns
Element
getFirstDirectChild()
staticgetFirstDirectChild(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()
staticgetMaxId(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()
staticgetNextRelId(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()
staticgetRelationshipItems(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()
staticgetRelationshipTargetsByPrefix(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()
staticgetTargetByRelId(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()
staticgetTargetsByRelationshipType(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()
staticgetXmlFromArchive(archive,file):Promise<Document>
Defined in: src/helper/xml-helper.ts:40
Parameters
archive
IArchive
file
string
Returns
Promise<Document>
insertAfter()
staticinsertAfter(newNode,referenceNode):Element
Defined in: src/helper/xml-helper.ts:453
Parameters
newNode
Element
referenceNode
Element
Returns
Element
insertInSchemaOrder()
staticinsertInSchemaOrder(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()
staticisElementCreationId(selector):boolean
Defined in: src/helper/xml-helper.ts:267
Parameters
selector
string
Returns
boolean
modifyCollection()
staticmodifyCollection(collection,callback):void
Defined in: src/helper/xml-helper.ts:656
Parameters
collection
XmlElementCollection
callback
ModifyXmlCallback
Returns
void
modifyCollectionAsync()
staticmodifyCollectionAsync(collection,callback):Promise<void>
Defined in: src/helper/xml-helper.ts:666
Parameters
collection
XmlElementCollection
callback
ModifyXmlCallback
Returns
Promise<void>
modifyXmlInArchive()
staticmodifyXmlInArchive(archive,file,callbacks):Promise<void>
Defined in: src/helper/xml-helper.ts:24
Parameters
archive
IArchive
file
string
callbacks
ModifyXmlCallback[]
Returns
Promise<void>
moveChild()
staticmoveChild(childToMove,insertBefore?):void
Defined in: src/helper/xml-helper.ts:622
Parameters
childToMove
Element
insertBefore?
Element
Returns
void
parseRelationTarget()
staticparseRelationTarget(element,prefix?):Target
Defined in: src/helper/xml-helper.ts:156
Parameters
element
Element
prefix?
string
Returns
Target
Deprecated
Use XmlRelationshipHelper.parseRelationTarget
remove()
staticremove(toRemove):void
Defined in: src/helper/xml-helper.ts:608
Parameters
toRemove
Element
Returns
void
removeAllChildren()
staticremoveAllChildren(element):void
Defined in: src/helper/xml-helper.ts:614
Parameters
element
Element
Returns
void
removeByTagName()
staticremoveByTagName(element,tagName,i?):void
Defined in: src/helper/xml-helper.ts:683
Parameters
element
Element
tagName
string
i?
number = 0
Returns
void
removeIf()
staticremoveIf(element):Promise<Element[]>
Defined in: src/helper/xml-helper.ts:101
Parameters
element
HelperElement
Returns
Promise<Element[]>
replaceAttribute()
staticreplaceAttribute(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()
staticsanitizeAttr(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()
staticsanitizeText(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()
staticsliceCollection(collection,length,from?):void
Defined in: src/helper/xml-helper.ts:480
Parameters
collection
XmlElementCollection
length
number
from?
number
Returns
void
sortChildrenBySchema()
staticsortChildrenBySchema(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()
staticsortCollection(collection,order,callback?):void
Defined in: src/helper/xml-helper.ts:633
Parameters
collection
XmlElementCollection
order
number[]
callback?
ModifyXmlCallback
Returns
void
targetMatchesRelationship()
statictargetMatchesRelationship(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()
staticwriteXmlToArchive(archive,file,xml):void
Defined in: src/helper/xml-helper.ts:47
Parameters
archive
IArchive
file
string
xml
Document
Returns
void