custom_xml
custom_xml
¶
The custom XML data store parts, customXml/itemN.xml and its properties sidecar.
A .docx can carry arbitrary XML in the custom XML data store, and bind document
content to it through w:dataBinding inside a w:sdt. This is how most
document-generation pipelines that are not string substitution actually work: the data
lives in the store, the content controls display it, and Word keeps the two in sync.
This is a different thing from the custom document properties in docProps/custom.xml
(docx.opc.customprops), which are a flat list of named scalars.
CustomXmlPropertiesPart
¶
CustomXmlPropertiesPart(
partname: PackURI,
content_type: str,
element: BaseOxmlElement,
package: Package,
)
Bases: XmlPart
A customXml/itemPropsN.xml part, the sidecar of a data store item.
Carries the GUID Word identifies the item by and the namespaces of the schemas it claims to conform to.
Source code in src/docx/opc/part.py
schema_refs
property
¶
The schema namespaces the store item claims, in document order.
new
classmethod
¶
new(
package: OpcPackage,
partname: PackURI,
item_id: str,
schema_refs: tuple[str, ...],
) -> CustomXmlPropertiesPart
A newly created properties part for a store item.
Source code in src/docx/opc/parts/custom_xml.py
CustomXmlPart
¶
CustomXmlPart(
partname: PackURI,
content_type: str,
element: BaseOxmlElement,
package: Package,
)
Bases: XmlPart
A customXml/itemN.xml part, one item of the custom XML data store.
The content is arbitrary caller-supplied XML, so it has no element classes of its own; element is a plain parsed tree and xml its serialization.
Source code in src/docx/opc/part.py
item_id
property
¶
The GUID this item is identified by, or None when it has no props part.
A store item without a properties part is out of spec but does occur; Word ignores such an item rather than repairing the document.
schema_refs
property
¶
The schema namespaces this item claims, empty when it has no props part.
xml
property
¶
The item's XML as a string.
Serialized with lxml directly rather than through BaseOxmlElement.xml: the
content is arbitrary caller-supplied XML, so its root arrives as a plain
lxml.etree._Element with none of this library's element classes behind it.
new
classmethod
¶
new(
package: OpcPackage,
partname: PackURI,
element: BaseOxmlElement,
) -> CustomXmlPart
A newly created store item part holding element.