Public bug reported: Here's the repro script:
#!/usr/bin/env python3 import sys from lxml import etree XSD = """\ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="Person" type="Person"/> <xsd:complexType name="Person"> <xsd:sequence> <xsd:element name="Name" type="xsd:string"/> <xsd:element name="Role" type="xsd:string" maxOccurs="2"/> <xsd:element name="Detail" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema>""" XML = """\ <Person> <Name>Guido</Name> <Role>TechnicalBackup</Role> </Person>""" print("%-20s: %s" % ('Python', sys.version_info)) print("%-20s: %s" % ('lxml.etree', etree.LXML_VERSION)) print("%-20s: %s" % ('libxml used', etree.LIBXML_VERSION)) print("%-20s: %s" % ('libxml compiled', etree.LIBXML_COMPILED_VERSION)) print("%-20s: %s" % ('libxslt used', etree.LIBXSLT_VERSION)) print("%-20s: %s" % ('libxslt compiled', etree.LIBXSLT_COMPILED_VERSION)) schema = etree.XMLSchema(etree.fromstring(XSD)) doc = etree.fromstring(XML) if not schema.validate(doc): print(schema.error_log) # END OF REPRO SCRIPT Here's the output: Python : sys.version_info(major=3, minor=10, micro=6, releaselevel='final', serial=0) lxml.etree : (4, 9, 1, 0) libxml used : (2, 9, 14) libxml compiled : (2, 9, 14) libxslt used : (1, 1, 35) libxslt compiled : (1, 1, 35) <string>:1:0:ERROR:SCHEMASV:SCHEMAV_ELEMENT_CONTENT: Element 'Person': Missing child element(s). Expected is ( Role ). # END OF OUTPUT It's clear from examining the schema and the XML document being validated that adding a second Role element is not necessary, and would do nothing to make the document valid. The correct assessment of the validation is that the required Details child element is missing. ** Affects: libxml2 (Ubuntu) Importance: Undecided Status: New -- You received this bug notification because you are a member of Desktop Packages, which is subscribed to libxml2 in Ubuntu. https://bugs.launchpad.net/bugs/1993651 Title: Schema validator reports the wrong child element as missing Status in libxml2 package in Ubuntu: New Bug description: Here's the repro script: #!/usr/bin/env python3 import sys from lxml import etree XSD = """\ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="Person" type="Person"/> <xsd:complexType name="Person"> <xsd:sequence> <xsd:element name="Name" type="xsd:string"/> <xsd:element name="Role" type="xsd:string" maxOccurs="2"/> <xsd:element name="Detail" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema>""" XML = """\ <Person> <Name>Guido</Name> <Role>TechnicalBackup</Role> </Person>""" print("%-20s: %s" % ('Python', sys.version_info)) print("%-20s: %s" % ('lxml.etree', etree.LXML_VERSION)) print("%-20s: %s" % ('libxml used', etree.LIBXML_VERSION)) print("%-20s: %s" % ('libxml compiled', etree.LIBXML_COMPILED_VERSION)) print("%-20s: %s" % ('libxslt used', etree.LIBXSLT_VERSION)) print("%-20s: %s" % ('libxslt compiled', etree.LIBXSLT_COMPILED_VERSION)) schema = etree.XMLSchema(etree.fromstring(XSD)) doc = etree.fromstring(XML) if not schema.validate(doc): print(schema.error_log) # END OF REPRO SCRIPT Here's the output: Python : sys.version_info(major=3, minor=10, micro=6, releaselevel='final', serial=0) lxml.etree : (4, 9, 1, 0) libxml used : (2, 9, 14) libxml compiled : (2, 9, 14) libxslt used : (1, 1, 35) libxslt compiled : (1, 1, 35) <string>:1:0:ERROR:SCHEMASV:SCHEMAV_ELEMENT_CONTENT: Element 'Person': Missing child element(s). Expected is ( Role ). # END OF OUTPUT It's clear from examining the schema and the XML document being validated that adding a second Role element is not necessary, and would do nothing to make the document valid. The correct assessment of the validation is that the required Details child element is missing. To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/libxml2/+bug/1993651/+subscriptions -- Mailing list: https://launchpad.net/~desktop-packages Post to : desktop-packages@lists.launchpad.net Unsubscribe : https://launchpad.net/~desktop-packages More help : https://help.launchpad.net/ListHelp