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 文件?
基础教程推荐
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
