12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
编程知识 时间:2024-12-05 09:50:24
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
在lxml中捕获Schematron验证的错误,可以使用lxml.etree.schematron模块的from_schematron函数来加载Schematron规则,然后使用lxml.etree.Schematron对象的assertValid方法来验
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
在lxml中捕获Schematron验证的错误,可以使用lxml.etree.schematron
模块的from_schematron
函数来加载Schematron规则,然后使用lxml.etree.Schematron
对象的assertValid
方法来验证XML文档。如果验证失败,会抛出lxml.etree.DocumentInvalid
异常,可以在异常中捕获验证错误信息。
下面是一个示例代码:
from lxml import etree# 加载Schematron规则schema_doc = etree.parse('your_schematron_schema.sch')schema = etree.Schematron(schema_doc)# 验证XML文档xml_doc = etree.parse('your_xml_doc.xml')try:schema.assertValid(xml_doc)print('XML文档通过Schematron验证')except etree.DocumentInvalid as e:print('XML文档未通过Schematron验证:')print(e)
在上面的代码中,首先加载Schematron规则并创建Schematron
对象,然后使用assertValid
方法验证XML文档。如果验证失败,会捕获DocumentInvalid
异常,并打印错误信息。
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19