Is it possible to validate an XML file against XSD 1.1 in Python?

Question:

I want validate an XML file against an XSD file using lxml.XMLSchema. But the problem is the XSD is in 1.1. So it doesn’t work.

This is a part of the XML:

<?xml version="1.0" encoding="UTF-8"?>
<dictionary 
            xsi_noNamespaceSchemaLocation="!!assert.xsd">
  <SizeType>10</SizeType>
</dictionary>

And this is its XSD file:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
           elementFormDefault="qualified">
  <xs:element name="SizeType">
    <xs:simpleType>
      <xs:restriction base="xs:integer">
        <xs:assertion test="$value = 10"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>

So, is it possible to validate an XML file against a XSD file that uses xs:assertion statements (1.1)?

I think this question is closely related to this: lxml with schema 1.1

Asked By: user1610952

||

Answers:

2022 update

Yes, starting in 2019 it finally became possible to validate XML against XSD 1.1 in Python.

Davide Brunato added XSD 1.1 support to xmlschema (v1.0.14).

Thanks to @Alex for pointing out the update.

2013 original answer

As of early November 2013, only the following XML processors support XSD 1.1:

There is no XML parser written in Python that validates against XSD 1.1 yet.

Answered By: kjhughes

xmlschema (1.0.14+) supports XSD 1.1

https://pypi.org/project/xmlschema

Answered By: Shlomo Gottlieb
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.