Data model¶
Every node of a pyxsd object tree — whether generated from a schema or
synthesized by a transform — exposes the same four dunder-prefixed
attributes. The double-underscore-free _*_ naming prevents collisions with
element or attribute names in your schemas (a schema can legally declare an
element called name, so name on an instance always refers to your
data, never to metadata).
The shape is codified by the pyxsd.XMLNode runtime-checkable
typing.Protocol.
Node structure¶
Attribute |
Type |
Meaning |
|---|---|---|
|
|
The element name as it appears in the document. |
|
|
Attributes keyed by the name as it should appear in the document. Values are stored lexically; |
|
|
Child instances of the same node shape, in document order. Empty list if the element has no children. |
|
|
Non-element content as a list of strings (usually one entry), or |
Notes:
Noneas_value_is meaningful: it represents an element nilled withxsi:nil="true", and the writer will emit the nil attribute.Attribute defaults applied by validation land in the instance
__dict__(typed values), not in_attribs_, so round-trip output stays faithful.Repeated elements (
maxOccurs> 1) store every occurrence in_children_in document order.
Writers¶
XmlTreeWriter(root, output) serializes any tree of nodes shaped as above.
Transform developers commonly use Transform.makeElemObj(name) to mint a
fresh node with this exact structure, and makeCommentElem(text) for
comments.
Generated classes¶
Class-level access to descriptors is intentional: item_cls.name returns
the descriptor, not the metadata, and the helpful __getattr__ on
generated classes raises an AttributeError listing the declared elements
and attributes when you misspell something. Instance-level access goes
through the descriptors, which validate types on assignment.