Skip to content

Commit f1fd316

Browse files
martinv13cre-os
andauthored
Allow xsd:any types (#52)
* Allow xsd:any types by dropping corresponding data * Bump version --------- Co-authored-by: cre-os <opensource@cre.fr>
1 parent 4691f70 commit f1fd316

8 files changed

Lines changed: 23 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "xml2db"
7-
version = "0.12.5"
7+
version = "0.12.6"
88
authors = [
99
{ name="Commission de régulation de l'énergie", email="opensource@cre.fr" },
1010
]

src/xml2db/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ def get_occurs(particle):
539539
)
540540
else:
541541
raise ValueError("unknown case; please check")
542+
elif type(child) is xmlschema.validators.wildcards.XsdAnyElement:
543+
logger.warning(
544+
f"type '{parent_type}' contains a xsd:any child, which is ignored"
545+
)
542546
else:
543547
raise ValueError("unknown case; please check (child not an XsdElement)")
544548

src/xml2db/table/column.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def can_join_values_as_string(self):
210210
"dateTime",
211211
"NMTOKEN",
212212
"time",
213+
"base64Binary", # was added as a fix for accepting more schemas, but not ideal
214+
"decimal", # was added as a fix for accepting more schemas, but not ideal
213215
):
214216
return True
215217
raise ValueError(

tests/sample_models/orders/equivalent_xml/order1a.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<companyId>
1414
<bic>JIDAZIO786DAZH</bic>
1515
</companyId>
16+
<extra>
17+
<profileName>profile 1</profileName>
18+
</extra>
1619
</orderperson>
1720
<item>
1821
<product>

tests/sample_models/orders/orders.xsd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
</xs:simpleContent>
2020
</xs:complexType>
2121

22+
<xs:complexType name="Extra">
23+
<xs:sequence>
24+
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip" />
25+
</xs:sequence>
26+
</xs:complexType>
27+
2228
<xs:complexType name="contacttype">
2329
<xs:sequence>
2430
<xs:element name="name" type="bt:stringtype"/>
@@ -29,6 +35,7 @@
2935
<xs:element name="phoneNumber" type="bt:stringtype" minOccurs="0" maxOccurs="unbounded"/>
3036
<xs:element name="companyId" type="companyIdType" minOccurs="0" maxOccurs="1"/>
3137
<xs:element name="coordinates" type="bt:CoordinatesListType" minOccurs="0"/>
38+
<xs:element name="extra" type="Extra" minOccurs="0"/>
3239
</xs:sequence>
3340
<xs:attribute name="name" type="xs:string" use="required"/>
3441
</xs:complexType>

tests/sample_models/orders/orders_source_tree_version0.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ orders:
2020
bic[0, 1]: string
2121
lei[0, 1]: string
2222
coordinates[0, 1]: string
23+
extra[0, 1]:
2324
shipto[0, 1]:
2425
name_attr[0, 1]: string
2526
name[1, 1]: string
@@ -36,6 +37,7 @@ orders:
3637
bic[0, 1]: string
3738
lei[0, 1]: string
3839
coordinates[0, 1]: string
40+
extra[0, 1]:
3941
item[1, None]:
4042
product[1, 1]:
4143
name[1, 1]: string

tests/sample_models/orders/orders_source_tree_version1.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ orders:
2020
bic[0, 1]: string
2121
lei[0, 1]: string
2222
coordinates[0, 1]: string
23+
extra[0, 1]:
2324
shipto[0, 1]:
2425
name_attr[0, 1]: string
2526
name[1, 1]: string
@@ -36,6 +37,7 @@ orders:
3637
bic[0, 1]: string
3738
lei[0, 1]: string
3839
coordinates[0, 1]: string
40+
extra[0, 1]:
3941
item[1, None]:
4042
product[1, 1]:
4143
name[1, 1]: string

tests/sample_models/orders/orders_source_tree_version2.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ orders:
2020
bic[0, 1]: string
2121
lei[0, 1]: string
2222
coordinates[0, 1]: string
23+
extra[0, 1]:
2324
shipto[0, 1]:
2425
name_attr[0, 1]: string
2526
name[1, 1]: string
@@ -36,6 +37,7 @@ orders:
3637
bic[0, 1]: string
3738
lei[0, 1]: string
3839
coordinates[0, 1]: string
40+
extra[0, 1]:
3941
item[1, None]:
4042
product[1, 1]:
4143
name[1, 1]: string

0 commit comments

Comments
 (0)