docx_plus.core.ns¶
Namespace constants and the qn() Clark-notation shortcut. Every other
module reaches for these when constructing or querying OOXML.
docx_plus.core.ns ¶
OOXML namespace URIs and Clark-notation helper.
All XML element construction in the library uses these constants and the
:func:qn helper, so that a single change here propagates everywhere.
NSMAP
module-attribute
¶
NSMAP: dict[str, str] = {
"w": W,
"w14": W14,
"w15": W15,
"w16cid": W16CID,
"r": R,
"mc": MC,
"a": A,
"xml": XML,
}
InvalidNamespaceError ¶
Bases: DocxPlusError, ValueError
Raised by :func:qn for a malformed name or unknown prefix.
Subclasses ValueError so existing except ValueError: clauses
still catch it; also subclasses :class:DocxPlusError per SPEC §9.7.
qn
cached
¶
Convert "prefix:local" to Clark notation "{namespace}local".
Memoized, and unboundedly so: the input domain is the OOXML tag
vocabulary, a few hundred literals fixed at authoring time. The
resolver calls this from inside its hot loops — 563,000 times in a
1000-paragraph sweep, 25% of the runtime — because writing qn("w:r")
at the callsite is what keeps that code legible. Caching buys the
legibility back for free. Failures are not cached, so a bad name raises
every time it is asked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Qualified name in |
required |
Returns:
| Type | Description |
|---|---|
str
|
The Clark-notation form |
Raises:
| Type | Description |
|---|---|
InvalidNamespaceError
|
If |
Example
qn("w:tag") '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tag'