After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 341150 - Failed schema validation with substitution groups and choice
Failed schema validation with substitution groups and choice
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: general
git master
Other All
: Normal normal
: ---
Assigned To: kbuchcik
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2006-05-09 16:29 UTC by Michael Romer
Modified: 2006-05-09 20:08 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Michael Romer 2006-05-09 16:29:19 UTC
Please describe the problem:
The supplied libxml2 validator, xmllint, will fail to validate the following
instance document against the schema specified below if you uncomment the line
specified in the instance document; however when it is commented, the instance
document will validate just fine.

Instance document:
------------------

<?xml version="1.0" encoding="UTF-8"?>
<TestRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="common-schema.xsd">
    <Events>
        <TestEvent>Test 1.</TestEvent>
        <!-- Uncomment the following element to cause libxml's xmllint to
            fail to validate. -->
        <!-- <TestEvent>Test 2.</TestEvent> -->
    </Events>
</TestRoot>



Schema to validate against:
---------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified">

    <!-- This is the head of our substitution group for events that have only
        simple content. -->
    <xs:element name="SimpleEvent" type="SimpleEventType"/>
    
    <!-- All SimpleEvent elements have the required set of attributes -->
    <xs:complexType name="SimpleEventType">
        <xs:simpleContent>
            <xs:extension base="xs:anySimpleType">
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    
    <!-- Common members of the SimpleEvent substitution group -->
    <xs:element name="TestEvent" substitutionGroup="SimpleEvent">
        <xs:complexType>
            <xs:simpleContent>
                <xs:restriction base="SimpleEventType">
                    <xs:simpleType>
                        <xs:restriction base="xs:string"/>
                    </xs:simpleType>
                </xs:restriction>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
    
    <!-- Root element -->
    <xs:element name="TestRoot" type="TestRootType"/>
    
    <!-- Core data type of an audit trail -->
    <xs:complexType name="TestRootType">
        <xs:sequence>
            <xs:element name="Events">
                <xs:complexType>
                    <xs:choice minOccurs="0" maxOccurs="unbounded">
                        <xs:element ref="SimpleEvent"/>
                    </xs:choice>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    
</xs:schema>



I have done numerous test cases and pinned the problem to be the fact that a
substitution group is being used inside the choice group element.  The choice
itself is specified to appear zero or more times in the instance document, with
each choice containing one SimpleEvent, or any element that can be substitutable
for SimpleEvent (in this case, TestEvent is declared to be part of the
SimpleEvent substitution group, so it should work just fine).

From what I can gather, the libxml2 validator is getting confused and instead of
thinking that the two TestEvent elements in the original instance document
belong to two separate choice groups, it actually thinks that they are both in
the same choice group.  If this is true, this would explain the error message
that is obtained (described below in the "What actually happens..." field).

I have tried changing the choice group to a sequence group, and the exact same
error occurs.

Steps to reproduce:
1. Save the above instance document in test.xml and the above schema in test.xsd.
2. Run the validator in the following manner: "xmllint --schema test.xsd test.xml"


Actual results:
The validator fails to validate the instance document against the schema.  The
error returned by the validator is the following:

"Description:  element TestEvent: Schemas validity error : Element 'TestEvent':
This element is not expected."

Expected results:
The supplied instance document should validate against the supplied schema.

Does this happen every time?
Yes.

Other information:
I have used the following validators, and they all validate the supplied
instance document against the supplied schema without any problem: Xerces, MSXML
4.0 SP2, MSXML.NET, and XSV.
Comment 1 kbuchcik 2006-05-09 20:08:51 UTC
In xmlSchemaBuildContentModelForSubstGroup(), xmlAutomataNewOnceTrans2() was incorrectly used instead of xmlAutomataNewTransition2(); seems like a copy&paste bug from the XML_SCHEMA_TYPE_ALL section in xmlSchemaBuildAContentModel().
The usage of xmlAutomataNewOnceTrans2() restricted the members of substitution-groups (except the group's head) to the occurence of 1.

Fixed in CVS, xmlschemas.c, revision 1.201.

Thanks for the thorough report!

I added your scenario to the regression tests.