Skip to content

config

xsdata.formats.dataclass.parsers.config

ParserConfig dataclass

Parsing configuration options.

Not all options are applicable for both xml and json documents.

Parameters:

Name Type Description Default
base_url Optional[str]

Specify a base URL when parsing from memory, and you need support for relative links e.g. xinclude

None
load_dtd bool

Enable loading external dtd (lxml only)

False
process_xinclude bool

Enable xinclude statements processing

False
class_factory Callable[[Type[T], Dict[str, Any]], T]

Override default object instantiation

default_class_factory
fail_on_unknown_properties bool

Skip unknown properties or fail with exception

True
fail_on_unknown_attributes bool

Skip unknown XML attributes or fail with exception

False
fail_on_converter_warnings bool

Turn converter warnings to exceptions

False
Source code in xsdata/formats/dataclass/parsers/config.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
@dataclass
class ParserConfig:
    """Parsing configuration options.

    Not all options are applicable for both xml and json documents.

    Args:
        base_url: Specify a base URL when parsing from memory, and
            you need support for relative links e.g. xinclude
        load_dtd: Enable loading external dtd (lxml only)
        process_xinclude: Enable xinclude statements processing
        class_factory: Override default object instantiation
        fail_on_unknown_properties: Skip unknown properties or fail with exception
        fail_on_unknown_attributes: Skip unknown XML attributes or fail with exception
        fail_on_converter_warnings: Turn converter warnings to exceptions
    """

    base_url: Optional[str] = None
    load_dtd: bool = False
    process_xinclude: bool = False
    class_factory: Callable[[Type[T], Dict[str, Any]], T] = field(
        default=default_class_factory
    )
    fail_on_unknown_properties: bool = True
    fail_on_unknown_attributes: bool = False
    fail_on_converter_warnings: bool = False

default_class_factory(cls, params)

The default class factory.

To be used as a hook for plugins.

Parameters:

Name Type Description Default
cls Type[T]

The target class type to instantiate

required
params Dict[str, Any]

The class keyword arguments

required

Returns:

Type Description
T

A new class instance with the given params.

Source code in xsdata/formats/dataclass/parsers/config.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def default_class_factory(cls: Type[T], params: Dict[str, Any]) -> T:
    """The default class factory.

    To be used as a hook for plugins.

    Args:
        cls: The target class type to instantiate
        params: The class keyword arguments

    Returns:
        A new class instance with the given params.
    """
    return cls(**params)  # type: ignore