Skip to content

# enums

## `xsdata.models.enums`

### `Namespace`

Bases: `Enum`

Common namespaces.

Source code in `xsdata/models/enums.py`

    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

    class Namespace(Enum):
        """Common namespaces."""

        XS = ("http://www.w3.org/2001/XMLSchema", "xs")
        XML = ("http://www.w3.org/XML/1998/namespace", "xml")
        XSI = ("http://www.w3.org/2001/XMLSchema-instance", "xsi")
        MATHML = ("http://www.w3.org/1998/Math/MathML", "mathml3")
        XLINK = ("http://www.w3.org/1999/xlink", "xlink")
        XHTML = ("http://www.w3.org/1999/xhtml", "xhtml")
        SOAP11 = ("http://schemas.xmlsoap.org/wsdl/soap/", "soap")
        SOAP12 = ("http://schemas.xmlsoap.org/wsdl/soap12/", "soap12")
        SOAP_ENV = ("http://schemas.xmlsoap.org/soap/envelope/", "soapenv")
        SOAP_ENC = ("http://schemas.xmlsoap.org/soap/encoding/", "soapenc")

        def __init__(self, uri: str, prefix: str):
            """Initialize namespace."""
            self.uri = uri
            self.prefix = prefix

        @property
        def location(self) -> str | None:
            """The location of the local file."""
            local_path = COMMON_SCHEMA_DIR.joinpath(f"{self.prefix}.xsd")
            return local_path.as_uri() if local_path.exists() else None

        @classmethod
        def get_enum(cls, uri: str | None) -> Optional["Namespace"]:
            """Get the enum member instance from the uri."""
            return __STANDARD_NAMESPACES__.get(uri) if uri else None

        @classmethod
        def common(cls) -> tuple["Namespace", ...]:
            """Return the common namespaces."""
            return Namespace.XS, Namespace.XSI, Namespace.XML, Namespace.XLINK

#### `location` `property`

The location of the local file.

#### `__init__(uri, prefix)`

Initialize namespace.

Source code in `xsdata/models/enums.py`

    36
    37
    38
    39

    def __init__(self, uri: str, prefix: str):
        """Initialize namespace."""
        self.uri = uri
        self.prefix = prefix

#### `get_enum(uri)` `classmethod`

Get the enum member instance from the uri.

Source code in `xsdata/models/enums.py`

    47
    48
    49
    50

    @classmethod
    def get_enum(cls, uri: str | None) -> Optional["Namespace"]:
        """Get the enum member instance from the uri."""
        return __STANDARD_NAMESPACES__.get(uri) if uri else None

#### `common()` `classmethod`

Return the common namespaces.

Source code in `xsdata/models/enums.py`

    52
    53
    54
    55

    @classmethod
    def common(cls) -> tuple["Namespace", ...]:
        """Return the common namespaces."""
        return Namespace.XS, Namespace.XSI, Namespace.XML, Namespace.XLINK

### `QNames`

Common qualified names.

Source code in `xsdata/models/enums.py`

    61
    62
    63
    64
    65
    66
    67
    68
    69

    class QNames:
        """Common qualified names."""

        XSI_NIL = sys.intern(f"{{{Namespace.XSI.uri}}}nil")
        XSI_TYPE = sys.intern(f"{{{Namespace.XSI.uri}}}type")
        XSI_SCHEMA_LOCATION = sys.intern(f"{{{Namespace.XSI.uri}}}schemaLocation")
        XSI_NO_NAMESPACE_SCHEMA_LOCATION = sys.intern(
            f"{{{Namespace.XSI.uri}}}noNamespaceSchemaLocation"
        )

### `NamespaceType`

Wildcard elements/attributes namespace types.

Attributes:

Name | Type | Description
--- | --- | ---
`ANY_NS` |  | elements from any namespace is allowed
`OTHER_NS` |  | elements from any namespace except the parent element's namespace
`LOCAL_NS` |  | elements must come from no namespace
`TARGET_NS` |  | elements from the namespace of the parent element can be present

Source code in `xsdata/models/enums.py`

    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85

    class NamespaceType:
        """Wildcard elements/attributes namespace types.

        Attributes:
            ANY_NS: elements from any namespace is allowed
            OTHER_NS: elements from any namespace except the parent element's namespace
            LOCAL_NS: elements must come from no namespace
            TARGET_NS: elements from the namespace of the parent element can be present
        """

        ANY_NS = "##any"
        OTHER_NS = "##other"
        LOCAL_NS = "##local"
        TARGET_NS = "##targetNamespace"

### `FormType`

Bases: `Enum`

Element/Attribute form types.

Source code in `xsdata/models/enums.py`

    88
    89
    90
    91
    92

    class FormType(Enum):
        """Element/Attribute form types."""

        QUALIFIED = "qualified"
        UNQUALIFIED = "unqualified"

### `Mode`

Bases: `Enum`

OpenContent mode types.

Source code in `xsdata/models/enums.py`

     95
     96
     97
     98
     99
    100

    class Mode(Enum):
        """OpenContent mode types."""

        NONE = "none"
        SUFFIX = "suffix"
        INTERLEAVE = "interleave"

### `DataType`

Bases: `Enum`

Xml and Schema data types to native python.

Source code in `xsdata/models/enums.py`

    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211

    class DataType(Enum):
        """Xml and Schema data types to native python."""

        # Primitives
        STRING = ("string", str)
        BOOLEAN = ("boolean", bool)
        DECIMAL = ("decimal", Decimal)
        FLOAT = ("float", float)
        DOUBLE = ("double", float)
        DURATION = ("duration", XmlDuration)
        DATE_TIME = ("dateTime", XmlDateTime)
        TIME = ("time", XmlTime)
        DATE = ("date", XmlDate)
        G_YEAR_MONTH = ("gYearMonth", XmlPeriod)
        G_YEAR = ("gYear", XmlPeriod)
        G_MONTH_DAY = ("gMonthDay", XmlPeriod)
        G_MONTH = ("gMonth", XmlPeriod)
        G_DAY = ("gDay", XmlPeriod)
        HEX_BINARY = ("hexBinary", bytes, "base16", XmlHexBinary)
        BASE64_BINARY = ("base64Binary", bytes, "base64", XmlBase64Binary)
        ANY_URI = ("anyURI", str)
        QNAME = ("QName", QName)
        NOTATION = ("NOTATION", QName)

        # Derived strings
        NORMALIZED_STRING = ("normalizedString", str)
        TOKEN = ("token", str)
        LANGUAGE = ("language", str)
        NMTOKEN = ("NMTOKEN", str)
        NMTOKENS = ("NMTOKENS", str)
        NAME = ("Name", str)
        NCNAME = ("NCName", str)
        ID = ("ID", str)
        IDREF = ("IDREF", str)
        IDREFS = ("IDREFS", str)
        ENTITIES = ("ENTITIES", str)
        ENTITY = ("ENTITY", str)

        # Derived integers
        INTEGER = ("integer", int)
        NON_POSITIVE_INTEGER = ("nonPositiveInteger", int)
        NEGATIVE_INTEGER = ("negativeInteger", int)
        LONG = ("long", int)
        INT = ("int", int)
        SHORT = ("short", int)
        BYTE = ("byte", int)
        NON_NEGATIVE_INTEGER = ("nonNegativeInteger", int)
        UNSIGNED_LONG = ("unsignedLong", int)
        UNSIGNED_INT = ("unsignedInt", int)
        UNSIGNED_SHORT = ("unsignedShort", int)
        UNSIGNED_BYTE = ("unsignedByte", int)
        POSITIVE_INTEGER = ("positiveInteger", int)

        # Derived Date/Time/Duration
        DATE_TIMESTAMP = ("dateTimeStamp", XmlDateTime)
        DAY_TIME_DURATION = ("dayTimeDuration", XmlDuration)
        YEAR_MONTH_DURATION = ("yearMonthDuration", XmlDuration)

        # Extensions
        ANY_TYPE = ("anyType", object)
        ANY_ATOMIC_TYPE = ("anyAtomicType", str)
        ANY_SIMPLE_TYPE = ("anySimpleType", object)
        ERROR = ("error", str)

        def __init__(
            self,
            code: str,
            python_type: type,
            fmt: str | None = None,
            wrapper: type | None = None,
        ):
            """Initialize DataType."""
            self.code = code
            self.type = python_type
            self.format = fmt
            self.wrapper = wrapper

        def __str__(self) -> str:
            """Return the qualified string representation of the datatype."""
            return f"{{{Namespace.XS.uri}}}{self.code}"

        def prefixed(self, prefix: str | None = Namespace.XS.prefix) -> str:
            """Return the prefixed string representation of the datatype."""
            return f"{prefix}:{self.code}" if prefix else self.code

        @classmethod
        def from_value(cls, value: Any) -> "DataType":
            """Load from a literal value."""
            _type = type(value)
            calculate = __DataTypeInferIndex__.get(_type)
            if calculate:
                return calculate(value)

            return cls.from_type(_type)

        @classmethod
        def from_type(cls, tp: type) -> "DataType":
            """Load from a python type."""
            return __DataTypeIndex__.get(tp, DataType.STRING)

        @classmethod
        def from_qname(cls, qname: str) -> Optional["DataType"]:
            """Load from a qualified name."""
            return __DataTypeQNameIndex__.get(qname)

        @classmethod
        def from_code(cls, code: str) -> "DataType":
            """Load from the code name."""
            return __DataTypeCodeIndex__.get(code, DataType.STRING)

#### `__init__(code, python_type, fmt=None, wrapper=None)`

Initialize DataType.

Source code in `xsdata/models/enums.py`

    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178

    def __init__(
        self,
        code: str,
        python_type: type,
        fmt: str | None = None,
        wrapper: type | None = None,
    ):
        """Initialize DataType."""
        self.code = code
        self.type = python_type
        self.format = fmt
        self.wrapper = wrapper

#### `__str__()`

Return the qualified string representation of the datatype.

Source code in `xsdata/models/enums.py`

    180
    181
    182

    def __str__(self) -> str:
        """Return the qualified string representation of the datatype."""
        return f"{{{Namespace.XS.uri}}}{self.code}"

#### `prefixed(prefix=Namespace.XS.prefix)`

Return the prefixed string representation of the datatype.

Source code in `xsdata/models/enums.py`

    184
    185
    186

    def prefixed(self, prefix: str | None = Namespace.XS.prefix) -> str:
        """Return the prefixed string representation of the datatype."""
        return f"{prefix}:{self.code}" if prefix else self.code

#### `from_value(value)` `classmethod`

Load from a literal value.

Source code in `xsdata/models/enums.py`

    188
    189
    190
    191
    192
    193
    194
    195
    196

    @classmethod
    def from_value(cls, value: Any) -> "DataType":
        """Load from a literal value."""
        _type = type(value)
        calculate = __DataTypeInferIndex__.get(_type)
        if calculate:
            return calculate(value)

        return cls.from_type(_type)

#### `from_type(tp)` `classmethod`

Load from a python type.

Source code in `xsdata/models/enums.py`

    198
    199
    200
    201

    @classmethod
    def from_type(cls, tp: type) -> "DataType":
        """Load from a python type."""
        return __DataTypeIndex__.get(tp, DataType.STRING)

#### `from_qname(qname)` `classmethod`

Load from a qualified name.

Source code in `xsdata/models/enums.py`

    203
    204
    205
    206

    @classmethod
    def from_qname(cls, qname: str) -> Optional["DataType"]:
        """Load from a qualified name."""
        return __DataTypeQNameIndex__.get(qname)

#### `from_code(code)` `classmethod`

Load from the code name.

Source code in `xsdata/models/enums.py`

    208
    209
    210
    211

    @classmethod
    def from_code(cls, code: str) -> "DataType":
        """Load from the code name."""
        return __DataTypeCodeIndex__.get(code, DataType.STRING)

### `EventType`

XmlParsing event types.

Source code in `xsdata/models/enums.py`

    266
    267
    268
    269
    270
    271

    class EventType:
        """XmlParsing event types."""

        START = sys.intern("start")
        START_NS = sys.intern("start-ns")
        END = sys.intern("end")

### `Tag`

Xml Schema tags.

Source code in `xsdata/models/enums.py`

    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328

    class Tag:
        """Xml Schema tags."""

        ALL = "All"
        ANNOTATION = "Annotation"
        ANY = "Any"
        ANY_ATTRIBUTE = "AnyAttribute"
        APPINFO = "Appinfo"
        ASSERTION = "Assertion"
        ALTERNATIVE = "Alternative"
        ATTRIBUTE = "Attribute"
        ATTRIBUTE_GROUP = "AttributeGroup"
        CHOICE = "Choice"
        COMPLEX_CONTENT = "ComplexContent"
        COMPLEX_TYPE = "ComplexType"
        DOCUMENTATION = "Documentation"
        ELEMENT = "Element"
        EXTENSION = "Extension"
        FIELD = "Field"
        GROUP = "Group"
        IMPORT = "Import"
        INCLUDE = "Include"
        KEY = "Key"
        KEYREF = "Keyref"
        LIST = "List"
        NOTATION = "Notation"
        OVERRIDE = "Override"
        REDEFINE = "Redefine"
        RESTRICTION = "Restriction"
        SCHEMA = "Schema"
        SELECTOR = "Selector"
        SEQUENCE = "Sequence"
        SIMPLE_CONTENT = "SimpleContent"
        SIMPLE_TYPE = "SimpleType"
        UNION = "Union"
        UNIQUE = "Unique"

        # Restrictions
        ENUMERATION = "Enumeration"
        FRACTION_DIGITS = "FractionDigits"
        LENGTH = "Length"
        MAX_EXCLUSIVE = "MaxExclusive"
        MAX_INCLUSIVE = "MaxInclusive"
        MAX_LENGTH = "MaxLength"
        MIN_EXCLUSIVE = "MinExclusive"
        MIN_INCLUSIVE = "MinInclusive"
        MIN_LENGTH = "MinLength"
        PATTERN = "Pattern"
        TOTAL_DIGITS = "TotalDigits"
        WHITE_SPACE = "WhiteSpace"

        # Wsdl
        BINDING_OPERATION = "BindingOperation"
        BINDING_MESSAGE = "BindingMessage"
        MESSAGE = "Message"

### `UseType`

Bases: `Enum`

Attribute use types.

Source code in `xsdata/models/enums.py`

    331
    332
    333
    334
    335
    336

    class UseType(Enum):
        """Attribute use types."""

        OPTIONAL = "optional"
        PROHIBITED = "prohibited"
        REQUIRED = "required"

### `ProcessType`

Bases: `Enum`

Wildcard process types.

Source code in `xsdata/models/enums.py`

    339
    340
    341
    342
    343
    344

    class ProcessType(Enum):
        """Wildcard process types."""

        LAX = "lax"
        SKIP = "skip"
        STRICT = "strict"

### `period_datatype(value)`

Infer the datatype of a xml period instance.

Source code in `xsdata/models/enums.py`

    214
    215
    216
    217
    218
    219
    220

    def period_datatype(value: XmlPeriod) -> DataType:
        """Infer the datatype of a xml period instance."""
        if value.year is not None:
            return DataType.G_YEAR_MONTH if value.month else DataType.G_YEAR
        if value.month:
            return DataType.G_MONTH_DAY if value.day else DataType.G_MONTH
        return DataType.G_DAY

### `int_datatype(value)`

Infer the datatype of an int value.

Source code in `xsdata/models/enums.py`

    223
    224
    225
    226
    227
    228
    229
    230
    231

    def int_datatype(value: int) -> DataType:
        """Infer the datatype of an int value."""
        if -32768 <= value <= 32767:
            return DataType.SHORT
        if -2147483648 <= value <= 2147483647:
            return DataType.INT
        if -9223372036854775808 <= value <= 9223372036854775807:
            return DataType.LONG
        return DataType.INTEGER

### `float_datatype(value)`

Infer the datatype of a float value.

Source code in `xsdata/models/enums.py`

    234
    235
    236
    237
    238

    def float_datatype(value: float) -> DataType:
        """Infer the datatype of a float value."""
        if -1.175494351e-38 <= value <= 3.402823466e38:
            return DataType.FLOAT
        return DataType.DOUBLE