Unable to use Assert element in XSD

75 views Asked by At

i am new in a XSD schema validation. i am looking for if else condition to be apply in XSD schema. After searching a lot in a internet i found "assert" element where we can test condition something like if else condition. but xsd validator giving me error something like this

enter image description here

Can you please help me out on this problem. Thank you

I tried using assert element in XSD and my expectation is to use "if else" like condition.

this is my simple XML data

<?xml version="1.0" encoding="UTF-8"?><person> <name>JohnDoe</name><age>30</age></person>

and this is my XSD schema

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="person">
<xs:complexType>
  <xs:sequence>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="age" type="xs:integer"/>
  </xs:sequence>
  
  <xs:assert test="age &gt;= 0 and age &lt;= 120"/>
</xs:complexType></xs:element></xs:schema>
1

There are 1 answers

0
Martin Honnen On

I think your schema will work (but the sample XML instance is valid) if you use a validator that supports XSD 1.1. Basically your open-source options are Apache Xerces Java in the latest version and you need to make sure you use the release with XSD 1.1 support (a web interface is online at https://www.softwarebytes.org/xmlvalidation/), or the Python package https://pypi.org/project/xmlschema/, I have a version of the Python package running in the browser at this XML workbench fiddle, use the XSD button to run the validation.

Additionally there are commercial options like Saxon EE or Altova.