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


基础教程推荐
- Python 的 List 是如何实现的? 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01