From 434dbbe4703ccdd498db96d2822c5f603411285b Mon Sep 17 00:00:00 2001 From: fabbiot Date: Tue, 13 Oct 2026 17:15:14 -0400 Subject: [PATCH] Accept xs:anyAttribute wildcards A type with an xs:anyAttribute made DataModel fail with "'NoneType' object has no attribute 'is_union'": xmlschema lists the wildcard in the type's attributes under the key None, without a type. Skip it with a warning, as done for xs:any children in #52. Co-Authored-By: Claude Opus 5.5 --- docs/how_it_works.md | 5 +++++ src/xml2db/model.py | 5 +++++ tests/sample_models/orders/equivalent_xml/order1a.xml | 2 +- tests/sample_models/orders/orders.xsd | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/how_it_works.md b/docs/how_it_works.md index 484da0a..ffff311 100644 --- a/docs/how_it_works.md +++ b/docs/how_it_works.md @@ -132,6 +132,11 @@ text and children elements within a node. When using [`Document.to_xml`](api/document.md#xml2db.document.Document.to_xml), text value will always appear before children elements. +#### Wildcards + +Wildcards (`xs:any` elements and `xs:anyAttribute` attributes) allow content that the schema does not describe. Schemas +containing them are accepted, but the matching content is not imported and a warning is logged. + ## Loading process This section explains in detail how parsing and loading work. Loading an XML file breaks down into the following steps. diff --git a/src/xml2db/model.py b/src/xml2db/model.py index 049fd6a..e5a30b0 100644 --- a/src/xml2db/model.py +++ b/src/xml2db/model.py @@ -428,6 +428,11 @@ def get_occurs(particle): # go through item attributes and add them as columns, adding a suffix if an element with the same name exists children_names = None for attrib_name, attrib in parent_node.attributes.items(): + if attrib_name is None: + logger.warning( + f"type '{parent_type}' contains a xsd:anyAttribute, which is ignored" + ) + continue if children_names is None: children_names = [child.local_name for child in parent_node] ( diff --git a/tests/sample_models/orders/equivalent_xml/order1a.xml b/tests/sample_models/orders/equivalent_xml/order1a.xml index 82234d8..788b944 100644 --- a/tests/sample_models/orders/equivalent_xml/order1a.xml +++ b/tests/sample_models/orders/equivalent_xml/order1a.xml @@ -13,7 +13,7 @@ JIDAZIO786DAZH - + profile 1 diff --git a/tests/sample_models/orders/orders.xsd b/tests/sample_models/orders/orders.xsd index beb0724..451f176 100644 --- a/tests/sample_models/orders/orders.xsd +++ b/tests/sample_models/orders/orders.xsd @@ -23,6 +23,7 @@ +