Skip to content

# standard

## `xsdata.formats.dataclass.parsers.nodes.standard`

### `StandardNode`

Bases: `XmlNode`

XmlNode for elements with a standard xsi:type.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`meta` | `XmlMeta` | The parent xml meta instance | required
`var` | `XmlVar` | The xml var instance | required
`datatype` | `DataType` | The element standard xsi data type | required
`ns_map` | `dict` | The element namespace prefix-URI map | required
`config` | `ParserConfig` | The parser config instance | required
`nillable` | `bool` | Specifies whether nil content is allowed | required
`derived_factory` | `type | None` | The derived element factory | required

Source code in `xsdata/formats/dataclass/parsers/nodes/standard.py`

     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
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97

    class StandardNode(XmlNode):
        """XmlNode for elements with a standard xsi:type.

        Args:
            meta: The parent xml meta instance
            var: The xml var instance
            datatype: The element standard xsi data type
            ns_map: The element namespace prefix-URI map
            config: The parser config instance
            nillable: Specifies whether nil content is allowed
            derived_factory: The derived element factory
        """

        __slots__ = (
            "config",
            "datatype",
            "derived_factory",
            "meta",
            "nillable",
            "ns_map",
            "var",
        )

        def __init__(
            self,
            meta: XmlMeta,
            var: XmlVar,
            datatype: DataType,
            ns_map: dict,
            config: ParserConfig,
            nillable: bool,
            derived_factory: type | None,
        ):
            """Initialize the xml node."""
            self.meta = meta
            self.var = var
            self.datatype = datatype
            self.ns_map = ns_map
            self.config = config
            self.nillable = nillable
            self.derived_factory = derived_factory

        def bind(
            self,
            qname: str,
            text: str | None,
            tail: str | None,
            objects: list,
        ) -> bool:
            """Bind the parsed data into an object for the ending element.

            This entry point is called when a xml element ends and is
            responsible to parse the current element text content.

            Args:
                qname: The element qualified name
                text: The element text content
                tail: The element tail content
                objects: The list of intermediate parsed objects

            Returns:
                Always true, it's not possible to fail during parsing
                for this node.
            """
            obj = ParserUtils.parse_var(
                meta=self.meta,
                var=self.var,
                config=self.config,
                value=text,
                types=[self.datatype.type],
                ns_map=self.ns_map,
                format=self.datatype.format,
            )

            if obj is None and not self.nillable:
                obj = ""

            if self.datatype.wrapper:
                obj = self.datatype.wrapper(obj)

            if self.derived_factory:
                obj = self.derived_factory(qname=qname, value=obj)

            objects.append((qname, obj))
            return True

        def child(self, qname: str, attrs: dict, ns_map: dict, position: int) -> XmlNode:
            """Raise an exception if there is a child element inside this node."""
            raise XmlContextError("StandardNode node doesn't support child nodes!")

#### `__init__(meta, var, datatype, ns_map, config, nillable, derived_factory)`

Initialize the xml node.

Source code in `xsdata/formats/dataclass/parsers/nodes/standard.py`

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

    def __init__(
        self,
        meta: XmlMeta,
        var: XmlVar,
        datatype: DataType,
        ns_map: dict,
        config: ParserConfig,
        nillable: bool,
        derived_factory: type | None,
    ):
        """Initialize the xml node."""
        self.meta = meta
        self.var = var
        self.datatype = datatype
        self.ns_map = ns_map
        self.config = config
        self.nillable = nillable
        self.derived_factory = derived_factory

#### `bind(qname, text, tail, objects)`

Bind the parsed data into an object for the ending element.

This entry point is called when a xml element ends and is responsible to parse the current element text content.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`qname` | `str` | The element qualified name | required
`text` | `str | None` | The element text content | required
`tail` | `str | None` | The element tail content | required
`objects` | `list` | The list of intermediate parsed objects | required

Returns:

Type | Description
--- | ---
`bool` | Always true, it's not possible to fail during parsing
`bool` | for this node.

Source code in `xsdata/formats/dataclass/parsers/nodes/standard.py`

    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93

    def bind(
        self,
        qname: str,
        text: str | None,
        tail: str | None,
        objects: list,
    ) -> bool:
        """Bind the parsed data into an object for the ending element.

        This entry point is called when a xml element ends and is
        responsible to parse the current element text content.

        Args:
            qname: The element qualified name
            text: The element text content
            tail: The element tail content
            objects: The list of intermediate parsed objects

        Returns:
            Always true, it's not possible to fail during parsing
            for this node.
        """
        obj = ParserUtils.parse_var(
            meta=self.meta,
            var=self.var,
            config=self.config,
            value=text,
            types=[self.datatype.type],
            ns_map=self.ns_map,
            format=self.datatype.format,
        )

        if obj is None and not self.nillable:
            obj = ""

        if self.datatype.wrapper:
            obj = self.datatype.wrapper(obj)

        if self.derived_factory:
            obj = self.derived_factory(qname=qname, value=obj)

        objects.append((qname, obj))
        return True

#### `child(qname, attrs, ns_map, position)`

Raise an exception if there is a child element inside this node.

Source code in `xsdata/formats/dataclass/parsers/nodes/standard.py`

    95
    96
    97

    def child(self, qname: str, attrs: dict, ns_map: dict, position: int) -> XmlNode:
        """Raise an exception if there is a child element inside this node."""
        raise XmlContextError("StandardNode node doesn't support child nodes!")