Is it possible to validate an XML file against XSD 1.1 in Python?(是否可以在 Python 中针对 XSD 1.1 验证 XML 文件?)
问题描述
我想使用 lxml.XMLSchema 针对 XSD 文件验证 XML 文件.但问题是 XSD 在 1.1 中.所以它不起作用.
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.
这是 XML 的一部分:
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>
这是它的 XSD 文件:
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>
那么,是否可以针对使用 xs:assertion
语句 (1.1) 的 XSD 文件来验证 XML 文件?
So, is it possible to validate an XML file against a XSD file that uses xs:assertion
statements (1.1)?
我认为这个问题与此密切相关:lxml with schema 1.1
I think this question is closely related to this: lxml with schema 1.1
推荐答案
截至 2013 年 11 月上旬,只有以下 XML 处理器支持 XSD 1.1:
As of early November 2013, only the following XML processors support XSD 1.1:
- Xerces-J 与 PsychoPath XPath 2.0
- 萨克森EE
- Altova
目前还没有用 Python 编写的可针对 XSD 1.1 进行验证的 XML 解析器.
There is no XML parser written in Python that validates against XSD 1.1 yet.
这篇关于是否可以在 Python 中针对 XSD 1.1 验证 XML 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以在 Python 中针对 XSD 1.1 验证 XML 文件?


基础教程推荐
- 对多索引数据帧的列进行排序 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01