One canonical helper matching the convention used throughout the Python
source where getElementsByTagName('w:p') is called with a prefixed
name. The Python code relies on the parser keeping the prefix attached;
@xmldom follows the DOM spec and exposes nodes via namespace URI +
localName instead.
Pass the namespace URI (use NS from ./types) and the local name; you
get a flat array, not a live NodeList.
Use "*" as the namespace to match across all namespaces (mirrors
Document.getElementsByTagName('*')).
A query rooted at a Document reads an index of its elements once a second
query finds the document unchanged since the first: a full DOCX run asks
the same main document for one element name after another, hundreds of
walks that dominated a 2 MB document's validation time. A caller that
changes the document between queries keeps the plain walk instead of
rebuilding the index for each one.
One canonical helper matching the convention used throughout the Python source where
getElementsByTagName('w:p')is called with a prefixed name. The Python code relies on the parser keeping the prefix attached;@xmldomfollows the DOM spec and exposes nodes via namespace URI + localName instead.Pass the namespace URI (use
NSfrom./types) and the local name; you get a flat array, not a liveNodeList.Use
"*"as the namespace to match across all namespaces (mirrorsDocument.getElementsByTagName('*')).A query rooted at a Document reads an index of its elements once a second query finds the document unchanged since the first: a full DOCX run asks the same main document for one element name after another, hundreds of walks that dominated a 2 MB document's validation time. A caller that changes the document between queries keeps the plain walk instead of rebuilding the index for each one.