MCPcopy Index your code
hub / github.com/python-openxml/python-docx / OxmlElement

Function OxmlElement

src/docx/oxml/parser.py:44–62  ·  view source on GitHub ↗

Return a 'loose' lxml element having the tag specified by `nsptag_str`. The tag in `nsptag_str` must contain the standard namespace prefix, e.g. `a:tbl`. The resulting element is an instance of the custom element class for this tag name if one is defined. A dictionary of attribute value

(
    nsptag_str: str,
    attrs: Dict[str, str] | None = None,
    nsdecls: Dict[str, str] | None = None,
)

Source from the content-addressed store, hash-verified

42
43
44def OxmlElement(
45 nsptag_str: str,
46 attrs: Dict[str, str] | None = None,
47 nsdecls: Dict[str, str] | None = None,
48) -> BaseOxmlElement | etree._Element: # pyright: ignore[reportPrivateUsage]
49 """Return a 'loose' lxml element having the tag specified by `nsptag_str`.
50
51 The tag in `nsptag_str` must contain the standard namespace prefix, e.g. `a:tbl`.
52 The resulting element is an instance of the custom element class for this tag name
53 if one is defined. A dictionary of attribute values may be provided as `attrs`; they
54 are set if present. All namespaces defined in the dict `nsdecls` are declared in the
55 element using the key as the prefix and the value as the namespace name. If
56 `nsdecls` is not provided, a single namespace declaration is added based on the
57 prefix on `nsptag_str`.
58 """
59 nsptag = NamespacePrefixedTag(nsptag_str)
60 if nsdecls is None:
61 nsdecls = nsptag.nsmap
62 return oxml_parser.makeelement(nsptag.clark_name, attrib=attrs, nsmap=nsdecls)

Calls 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…