简体   繁体   English

使用 lxml python 库加载无效的机器人框架 XML 架构 (xsd)

[英]Load invalid Robot Framework XML Schema (xsd) using lxml python library

I'm trying to validate the output.xml file from Robot Framework with officially provided XML schema :我正在尝试使用官方提供的XML 模式验证 Robot Framework 中的 output.xml 文件:

For xml validation in Python I'm using lxml library .对于 Python 中的 xml 验证,我使用的是lxml 库

    def validate_xml_file(schema, filename: str):
        log.info("Validating XML file: {}".format(filename))
        xsd_doc = etree.parse(schema)
        xsd = etree.XMLSchema(xsd_doc)
        xml = etree.parse(filename)
        result = xsd.assertValid(xml)

I'm getting following error:我收到以下错误:

  File "src/lxml/xmlschema.pxi", line 86, in lxml.etree.XMLSchema.__init__
lxml.etree.XMLSchemaParseError: Element '{http://www.w3.org/2001/XMLSchema}element': Invalid value for maxOccurs (must be 0 or 1)., line 19

As you can see in Robot Framework xsd file, line 19 is: <xs:element name="kw" type="kw" maxOccurs="2" minOccurs="0"/> which means, there is an issue with macOccurs="2" .正如您在 Robot Framework xsd 文件中看到的,第 19 行是: <xs:element name="kw" type="kw" maxOccurs="2" minOccurs="0"/>这意味着macOccurs=存在问题“2” Do you know about some "nice" way, how to ignore this rule?你知道一些“不错”的方式,如何忽略这条规则?

Thanks.谢谢。

Ok, I found the issue.好的,我发现了问题。 lxml doesn't support XSD 1.1, it supports only XSD 1.0. lxml 不支持 XSD 1.1,它只支持 XSD 1.0。 So I just took the RobotFramework XSD 1.0 and now it works as expected.所以我只使用了 RobotFramework XSD 1.0,现在它按预期工作了。

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

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