etree.XMLSchema raises exception for maxOccurs > 2^30
Although the standard indicates that maxOccurs can be nonNegativeInteger or unbounded, most implementations (e.g. Java's xjc, Xerces) allow for maxOccurs up to (2^31)-1. The libxml2 library seems to be limiting it to 2^30, which presumably is a calculation error. The following two schemas demonstrate a failed and successful schema validations:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:org:sample" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0" version="1.0"> <xs:complexType name="SampleArray"> xs:sequence <xs:element name="entry" maxOccurs="2147483647" minOccurs="2147483647" type="xs:int"/> </xs:sequence> </xs:complexType> </xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:org:sample" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0" version="1.0"> <xs:complexType name="SampleArray"> xs:sequence <xs:element name="entry" maxOccurs="1073741824" minOccurs="1073741824" type="xs:int"/> </xs:sequence> </xs:complexType> </xs:schema>
Both pass validation with Java's xjc code generator, but fail when validated by lxml as follows:
#!/usr/bin/env python
import lxml from lxml import etree
schemaDocument = etree.parse( 'schema.xsd' ) #schemaDocument = etree.parse( 'schema_max.xsd' )
etree.XMLSchema( schemaDocument )
Lastly, below is the requested version info: Python : sys.version_info(major=3, minor=7, micro=0, releaselevel='final', serial=0) lxml.etree : (4, 2, 5, 0) libxml used : (2, 9, 8) libxml compiled : (2, 9, 8) libxslt used : (1, 1, 32) libxslt compiled : (1, 1, 32)
Apologizes for any typos, since this was re-typed from an air-gaped system