1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
from dataclasses import dataclass, field
from typing import Dict, Generic, List, Optional, TypeVar
from xsdata.formats.dataclass.models.elements import XmlType
T = TypeVar("T", bound=object)
@dataclass
class AnyElement:
"""
Generic model to bind xml document data to wildcard fields.
:param qname: The element's qualified name
:param text: The element's text content
:param tail: The element's tail content
:param children: The element's list of child elements.
:param attributes: The element's key-value attribute mappings.
"""
qname: Optional[str] = field(default=None)
text: Optional[str] = field(default=None)
tail: Optional[str] = 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}
)
@dataclass
class DerivedElement(Generic[T]):
"""
Generic model wrapper for type substituted elements.
Example: eg. <b xsi:type="a">...</b>
:param qname: The element's qualified name
:param value: The wrapped value
:param type: The real xsi:type
"""
qname: str
value: T
type: Optional[str] = None
|