You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,6 @@ Requires Python 3.7 or higher.
27
27
28
28
* Whitespace and comments aren't supported in the data model. They must be stripped when loading the XML
29
29
* So far, I haven't found any examples where XML can't be mapped to a dataclass, but it's likely possible given how complex XML is
30
-
* Strict mapping. Currently, if an unknown element is encountered, an error is raised (see [#3](https://github.com/tobywf/xml_dataclasses/issues/3), pull requests welcome)
31
30
* No typing/type conversions. Since XML is untyped, only string values are currently allowed. Type conversions are tricky to implement in a type-safe and extensible manner.
32
31
* Dataclasses must be written by hand, no tools are provided to generate these from, DTDs, XML schema definitions, or RELAX NG schemas
33
32
@@ -54,6 +53,8 @@ class Foo:
54
53
55
54
For now, you can work around this limitation with properties that do the conversion, and perform post-load validation.
56
55
56
+
By default, unknown attributes raise an error. This can be disabled by passing `Options` to `load` with `ignore_unknown_attributes`.
57
+
57
58
### Defining text
58
59
59
60
Like attributes, text can be either `str` or `Optional[str]`. You must declare text content with the `text` function. Similar to `rename`, this function can use an existing field definition, or take the `default` argument. Text cannot be renamed or namespaced. Every class can only have one field defining text content. If a class has text content, it cannot have any children.
@@ -87,6 +88,8 @@ If a class has children, it cannot have text content.
87
88
88
89
Children can be renamed via the `rename` function. However, attempting to set a namespace is invalid, since the namespace is provided by the child type's XML dataclass. Also, unions of XML dataclasses must have the same namespace (you can use different fields with renaming if they have different namespaces, since the XML names will be resolved as a combination of namespace and name).
89
90
91
+
By default, unknown children raise an error. This can be disabled by passing `Options` to `load` with `ignore_unknown_children`.
92
+
90
93
### Defining post-load validation
91
94
92
95
Simply implement an instance method called `xml_validate` with no parameters, and no return value (if you're using type hints):
@@ -216,6 +219,7 @@ This makes sense in many cases, but possibly not every case.
216
219
### [0.0.7] - unreleased
217
220
218
221
* Warn if comments are found/don't treat comments as child elements in error messages
222
+
* Allow lenient loading of undeclared attributes or children
0 commit comments