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

混江龙づ霸主 提交于 2019-11-27 08:19:35

问题


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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="!!assert.xsd">
  <SizeType>10</SizeType>
</dictionary>

And this is its XSD file:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           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


回答1:


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

  • Xerces-J with PsychoPath XPath 2.0
  • Saxon EE
  • Altova

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



来源:https://stackoverflow.com/questions/19809141/is-it-possible-to-validate-an-xml-file-against-xsd-1-1-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!