简体   繁体   English

是否可以在 Python 中针对 XSD 1.1 验证 XML 文件?

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

I want validate an XML file against an XSD file using lxml.XMLSchema.我想使用 lxml.XMLSchema 针对 XSD 文件验证 XML 文件。 But the problem is the XSD is in 1.1.但问题是 XSD 是 1.1。 So it doesn't work.所以它不起作用。

This is a part of the XML:这是 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:这是它的 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>

So, is it possible to validate an XML file against a XSD file that uses xs:assertion statements (1.1)?那么,是否可以针对使用xs:assertion语句 (1.1) 的 XSD 文件验证 XML 文件?

I think this question is closely related to this: lxml with schema 1.1我认为这个问题与此密切相关: lxml with schema 1.1

xmlschema (1.0.14+) supports XSD 1.1 xmlschema (1.0.14+) 支持 XSD 1.1

https://pypi.org/project/xmlschema https://pypi.org/project/xmlschema

As of early November 2013, only the following XML processors support XSD 1.1:截至 2013 年 11 月上旬,只有以下 XML 处理器支持 XSD 1.1:

There is no XML parser written in Python that validates against XSD 1.1 yet.目前还没有用 Python 编写的 XML 解析器可以针对 XSD 1.1 进行验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM