Skip to content

Incorrect Validation Error for Substitution Group with Abstract Head #417

@StanimirIglev

Description

@StanimirIglev

Description:

The xmlschema library incorrectly invalidates XML documents that use elements from a substitution group whose head is abstract. According to the W3C XML Schema specifications, substitution group members can appear in the instance document even if the head element is abstract.

To reproduce:

  1. XML Schema (schema.xsd):
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="abstractSubgroupHead" type="xs:integer" abstract="true"/>
    <xs:element name="subgroupMember" type="xs:positiveInteger" substitutionGroup="abstractSubgroupHead"/>
</xs:schema>
  1. XML document (document.xml):
<subgroupMember>1</subgroupMember>
  1. Validate:
xmlschema-validate --schema schema.xsd document.xml -v

Expected behavior:

The XML document should be validated successfully because subgroupMember is a global element; thus, a valid root within the instance document.

Actual behavior:

The xmlschema library reports the following error:

document.xml is not valid
failed validating <Element 'subgroupMember' at 0x7f6285136110> with XsdElement(name='abstractSubgroupHead', occurs=[1, 1]):

Reason: cannot use an abstract element for validation

Schema component:

  <xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name="abstractSubgroupHead" type="xs:integer" abstract="true" />

Instance type: <class 'xml.etree.ElementTree.Element'>

Instance:

  <subgroupMember>1</subgroupMember>

Path: /subgroupMember

Environment:

  • xmlschema version: 3.4.0
  • Python version: 3.11.8

Additional notes:

  • The bug happens regardless of whether one uses the CLI or the API (is_valid and validate).
  • I believe the problem occurs only when the substitution element is used as a root element of the instance document, i.e., if there is another global element with complex type, which contains a reference to the abstract subgroup head, the validation is correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions