Skip to content

# generics

## `xsdata.formats.dataclass.models.generics`

### `AnyElement` `dataclass`

Generic model to bind xml document data to wildcard fields.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`qname` | `str | None` | The element's qualified name | `None`
`text` | `str | None` | The element's text content | `None`
`tail` | `str | None` | The element's tail content | `None`
`children` | `list[object]` | The element's list of child elements. | `list()`
`attributes` | `dict[str, str]` | The element's key-value attribute mappings. | `dict()`

Source code in `xsdata/formats/dataclass/models/generics.py`

     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29

    @dataclass
    class AnyElement:
        """Generic model to bind xml document data to wildcard fields.

        Args:
            qname: The element's qualified name
            text: The element's text content
            tail: The element's tail content
            children: The element's list of child elements.
            attributes: The element's key-value attribute mappings.
        """

        qname: str | None = field(default=None)
        text: str | None = field(default=None)
        tail: str | None = field(default=None)
        children: list[object] = field(
            default_factory=list, metadata={"type": XmlType.WILDCARD}
        )
        attributes: dict[str, str] = field(
            default_factory=dict, metadata={"type": XmlType.ATTRIBUTES}
        )

### `DerivedElement` `dataclass`

Bases: `Generic[T]`

Generic model wrapper for type substituted elements.

Example: e.g. ...

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`qname` | `str` | The element's qualified name | required
`value` | `T` | The wrapped value | required
`type` | `str | None` | The real xsi:type | `None`

Source code in `xsdata/formats/dataclass/models/generics.py`

    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46

    @dataclass
    class DerivedElement(Generic[T]):
        """Generic model wrapper for type substituted elements.

        Example: e.g. <b xsi:type="a">...</b>

        Args:
            qname: The element's qualified name
            value: The wrapped value
            type: The real xsi:type
        """

        qname: str
        value: T
        type: str | None = None