chaotic
chaotic

Reputation: 411

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:

For xml validation in Python I'm using lxml library.

    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". Do you know about some "nice" way, how to ignore this rule?

Thanks.

Upvotes: 1

Views: 700

Answers (1)

chaotic
chaotic

Reputation: 411

Ok, I found the issue. lxml doesn't support XSD 1.1, it supports only XSD 1.0. So I just took the RobotFramework XSD 1.0 and now it works as expected.

Upvotes: 2

Related Questions