【问题标题】:Is it possible to validate an XML file against XSD 1.1 in Python?是否可以在 Python 中针对 XSD 1.1 验证 XML 文件?
【发布时间】:2013-11-17 12:23:47
【问题描述】:

我想使用 lxml.XMLSchema 针对 XSD 文件验证 XML 文件。但问题是 XSD 在 1.1 中。所以它不起作用。

这是 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>

这是它的 XSD 文件:

<?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>

那么,是否可以针对使用 xs:assertion 语句 (1.1) 的 XSD 文件验证 XML 文件?

我认为这个问题与此密切相关:lxml with schema 1.1

【问题讨论】:

    标签: python xsd schema lxml


    【解决方案1】:

    xmlschema (1.0.14+) 支持 XSD 1.1

    https://pypi.org/project/xmlschema

    【讨论】:

      【解决方案2】:

      截至 2013 年 11 月上旬,只有以下 XML 处理器支持 XSD 1.1:

      目前还没有用 Python 编写的可针对 XSD 1.1 进行验证的 XML 解析器。

      【讨论】:

      • 这两年在这方面有什么进展吗?
      • 不,我听说没有新的努力支持 Python 中的 XSD 1.1 验证。对不起。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      • 2012-07-23
      • 1970-01-01
      相关资源
      最近更新 更多