-
Notifications
You must be signed in to change notification settings - Fork 82
Closed
Description
Hi all,
I have an element which either should be set to xsi:nil="true" or be set to an integer value. Validation works in for example the Xerex library, but unfortunately fails in xmlschema.
The XSD file is:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified"
attributeFormDefault="unqualified" vc:minVersion="1.1"
xmlns:am="http://www.test.com/XMLSchema/manifest/2021"
targetNamespace="http://www.test.com/XMLSchema/manifest/2021"
xmlns="http://www.test.com/XMLSchema/manifest/2021">
<xs:element name="manifest">
<xs:complexType>
<xs:sequence>
<xs:element name="session">
<xs:complexType>
<xs:sequence>
<xs:element name="userId" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="sessionId" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute name="anonymous" type="xs:boolean" use="required">
</xs:attribute>
<xs:assert
test="((@anonymous eq true()) and am:userId[@xsi:nil] and am:sessionId[@xsi:nil]) or ((@anonymous eq false()) and am:userId[node()] and am:sessionId[node()])"
/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>The XML to be validated is:
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.test.com/XMLSchema/manifest/2021">
<session anonymous="true">
<userId xsi:nil="true"/>
<sessionId xsi:nil="true"/>
</session>
</manifest>In the XSD file, note the assert:
<xs:assert
test="((@anonymous eq true()) and am:userId[@xsi:nil] and am:sessionId[@xsi:nil]) or ((@anonymous eq false()) and am:userId[node()] and am:sessionId[node()])"
/>which should test that if anonymous is set to True that the userId and sessionId should be xsi:nil. If anonymous is False, userId and sessionId should hold a value.
I run the above using:
import xmlschema
xsd = xmlschema.XMLSchema11('test.xsd')
xsd.validate('test.xml')Which gives output:
Traceback (most recent call last):
File "application.py", line 22, in <module>
xsd.validate('test.xml')
File "/usr/local/lib/python3.8/dist-packages/xmlschema/validators/schema.py", line 1520, in validate
raise error
xmlschema.validators.exceptions.XMLSchemaValidationError: failed validating <Element '{http://www.test.com/XMLSchema/manifest/2021}session' at 0x7f2294279950> with XsdAssert(test='((@anonymous eq true()) and am:userId...'):
Reason: ':' operator at line 1, column 55: [err:XPDY0050] Type Xsd11AtomicRestriction(primitive_type='decimal') does not match sequence type of <Element '{http://www.test.com/XMLSchema/manifest/2021}sessionId' at 0x7f2294279a40>
Schema:
<xs:assert xmlns:xs="http://www.w3.org/2001/XMLSchema" test="((@anonymous eq true()) and am:userId[@xsi:nil] and am:sessionId[@xsi:nil]) or ((@anonymous eq false()) and am:userId[node()] and am:sessionId[node()])" />
Instance:
<session xmlns="http://www.test.com/XMLSchema/manifest/2021" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" anonymous="true">
<userId xsi:nil="true" />
<sessionId xsi:nil="true" />
</session>
In Xerex the above XML/XSD validates. In xmlschema it validates only if I:
- remove the assert
- remove the restriction on sessionId
- change the
restrictionin sessionId from integer to something else like string.
Is there a possibility of fixing this such that this will pass the validation?
With best wishes,
Robbert
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels