Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/data_binding/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ Enable loading external dtd with

**Default:** `False`

### `resolve_entities`

Enable loading of external reference within XML documents with
[LxmlEventHandler][xsdata.formats.dataclass.parsers.handlers.LxmlEventHandler]. Enabling
this option has security implications: the code becomes vulnerable for External Entity
Injection (XXE).

**Type:** `bool`

**Default:** `False`

### `class_factory`

Override default object instantiation, to apply pre/post-initialization logic.
Expand Down
2 changes: 2 additions & 0 deletions xsdata/formats/dataclass/parsers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ParserConfig:
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)
resolve_entities: Enable resoling external entities (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
Expand All @@ -39,6 +40,7 @@ class ParserConfig:

base_url: str | None = None
load_dtd: bool = False
resolve_entities: bool = False
process_xinclude: bool = False
class_factory: Callable[[type[T], dict[str, Any]], T] = field(
default=default_class_factory
Expand Down
1 change: 1 addition & 0 deletions xsdata/formats/dataclass/parsers/handlers/lxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def parse(self, source: Any, ns_map: dict[str | None, str]) -> Any:
recover=True,
remove_comments=True,
load_dtd=self.parser.config.load_dtd,
resolve_entities=self.parser.config.resolve_entities,
)

return self.process_context(ctx, ns_map)
Expand Down
Loading