Schema validator reports the wrong child element as missing

Bug #1993651 reported by Bob Kline
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libxml2 (Ubuntu)
New
Undecided
Unassigned

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 post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.