0

I'm creating a XSD schema for validating a XML file.

The schema is correct for the W3C XML Schema (XSD) Validation page, while for QXmlSchema there's an error. This is a minimal XSD part that generates the error:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://standards.ieee.org/IEEE1516-2010" xmlns:ns="http://standards.ieee.org/IEEE1516-2010" targetNamespace="http://standards.ieee.org/IEEE1516-2010" elementFormDefault="qualified" attributeFormDefault="unqualified" version="2010">
  <xs:element name="objectModel" type="objectModelType">
  </xs:element>

  <xs:complexType name="objectModelType">
    <xs:sequence>
      <xs:element name="modelIdentification" type="modelIdentificationType">
        <xs:annotation>
          <xs:documentation>documents certain key identifying information within the object model description</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:any namespace="##other" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="modelIdentificationType">
    <xs:sequence>
      <xs:element name="name" type="NonEmptyString">
        <xs:annotation>
          <xs:documentation>specifies the name assigned to the object model</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="glyph" minOccurs="0">
        <xs:annotation>
          <xs:documentation>specifies a glyph to visually represent the model</xs:documentation>
        </xs:annotation>
        <xs:complexType mixed="true">
          <xs:simpleContent>
            <xs:extension base="glyphType"/>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
      <xs:any namespace="##other" minOccurs="0"/>
    </xs:sequence>
    <xs:attributeGroup ref="commonAttributes"/>
  </xs:complexType>
  <xs:complexType name="String">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attributeGroup ref="commonAttributes"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="NonEmptyString">
    <xs:simpleContent>
      <xs:extension base="nonEmptyString">
        <xs:attributeGroup ref="commonAttributes"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="glyphType" mixed="true">
    <xs:simpleContent>
      <xs:extension base="xs:base64Binary">
        <xs:attributeGroup ref="commonAttributes"/>
        <xs:attribute name="href" type="xs:anyURI"/>
        <xs:attribute name="type" type="glyphTypeUnion"/>
        <xs:attribute name="height" type="xs:short"/>
        <xs:attribute name="width" type="xs:short"/>
        <xs:attribute name="alt" type="xs:string"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="IdentifierType">
    <xs:simpleContent>
      <xs:extension base="xs:NCName">
        <xs:attributeGroup ref="commonAttributes"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>



  <xs:simpleType name="nonEmptyString">
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="glyphTypeUnion">
    <xs:union memberTypes="glyphTypeEnumerations xs:string"/>
  </xs:simpleType>

  <xs:simpleType name="glyphTypeEnumerations">
    <xs:restriction base="xs:string">
      <xs:enumeration value="BITMAP"/>
      <xs:enumeration value="JPG"/>
      <xs:enumeration value="GIF"/>
      <xs:enumeration value="PNG"/>
      <xs:enumeration value="TIFF"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:attributeGroup name="commonAttributes">
    <xs:attribute name="notes" type="xs:IDREFS" use="optional"/>
    <xs:attribute name="idtag" type="xs:ID" use="optional"/>
    <xs:anyAttribute namespace="##other"/>
  </xs:attributeGroup>

</xs:schema>

If I copy and paste this schema to the W3C page, it says that's ok.

I create the schema in my program this way:

QXmlSchema schema;
// text is a char array containing the XML file.
schema.load(text);

When i call the load method, the following message appears in the debug console window:

Error XSDError in Unknown location, at line 52, column 22: complexType element with simpleContent child element must not have a mixed attribute.

If I go to the line number shown in the message I can see that the complexType is the following one:

<xs:complexType name="glyphType" mixed="true">
  <xs:simpleContent>
    <xs:extension base="xs:base64Binary">
      <xs:attributeGroup ref="commonAttributes"/>
      <xs:attribute name="href" type="xs:anyURI"/>
      <xs:attribute name="type" type="glyphTypeUnion"/>
      <xs:attribute name="height" type="xs:short"/>
      <xs:attribute name="width" type="xs:short"/>
      <xs:attribute name="alt" type="xs:string"/>
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

The error message seems clear to me by seeing this part of the XSD, but I don't know why this should be an error.

So for the W3C page this is correct, for Qt is wrong. Which one has the correct interpretation of the complex type with simple content?

This is a minimal example of XML that should be validated (it is in the web page):

<?xml version="1.0" encoding="utf-8"?>
<objectModel xmlns="http://standards.ieee.org/IEEE1516-2010" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://standards.ieee.org/IEEE1516-2010 http://standards.ieee.org/downloads/1516/1516.2-2010/IEEE1516-DIF-2010.xsd">
  <modelIdentification>
    <name>New</name>
  </modelIdentification>
</objectModel>
Jepessen
  • 11,744
  • 14
  • 82
  • 149
  • Sure? The schema can be validated without the XML in the web page, because it checks only its correctness, while QXmlSchema gives me the error when I load the schema, before using it. – Jepessen Feb 15 '19 at 22:33
  • I found [this SO answer](https://stackoverflow.com/q/6084431/1305969) which might be helpful. Or [here](https://stackoverflow.com/a/12484940/1305969). – zx485 Feb 15 '19 at 22:34

1 Answers1

1

Simple content says the elements contain text (character data) only, mixed says the elements can contain a mixture of text and child elements, so it's contradictory to say both.

Saxon rejects it:

Error at xs:complexType on line 2 column 51 of test.xsd:
  The <complexType> must not specify mixed='true' when <simpleContent> is present

I found this Note in XSD 1.0 §3.4.3

Note: Although not explicitly ruled out either here or in Schema for Schemas (normative) (§A), specifying <xs:complexType . . .mixed='true' when the <simpleContent> alternative is chosen has no effect on the corresponding component, and should be avoided. This may be ruled out in a subsequent version of this specification.

So it's nonsense and strongly discouraged but it doesn't actually seem to be illegal according to XSD 1.0.

XSD 1.1 makes it illegal: §3.4.3 clause 1: If the <simpleContent> alternative is chosen, the <complexType> element must not have mixed = true.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164