Search code examples
xmlxsdxmlspyabstract-type

XSD in Altova XMLSpy 2014: Why can I use an abstract type in a concrete element?


In Altova XMLSpy 2014, I have a XSD document that defines:

  • An abstract type, "t_abs".
  • A concrete type, "t_con", defined as a sequence of elements, and one of the elements is defined as type "t_abs".
  • An element (instanciable), "e_con", defined of type "t_con".

Is that correct? I think it should generate an error, since the abstract type is not being used as a base (by extension or restriction) for the concrete type, the abstract type (t_abs) is being used as the type of a concrete element into an instanciable concrete element (t_con).

Should XMLSpy return a warning of an abstract type being used into a concrete element?

Example:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" attributeFormDefault="unqualified" vc:minVersion="1.1">
    <xs:complexType name="t_abs" abstract="true">
        <xs:sequence>
            <xs:element name="el" type="xs:string"/>
            <xs:element name="e2" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="t_con">
        <xs:sequence>
            <xs:element name="e_t_con_1" type="xs:string"/>
            <xs:element name="e_t_abs" type="t_abs"/>
            <xs:element name="e_t_con_2" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="e_con" type="t_con"/>
</xs:schema>

Solution

  • XMLSpy is allowed not to report the error that you expect prior to actual validation (emphasis added):

    3.4.1 The Complex Type Definition Schema Component

    Complex types for which {abstract} is true must not be used as the {type definition} for the ·validation· of element information items. It follows that they must not be referenced from an xsi:type (§2.6.1) attribute in an instance document. Abstract complex types can be used as {base type definition}s, or even as the {type definition}s of element declarations, provided in every case a concrete derived type definition is used for ·validation·, either via xsi:type (§2.6.1) or the operation of a substitution group.

    If you go ahead and try to use your XSD for validation of a document instance,

    <?xml version="1.0" encoding="utf-8"?>
    <e_con>
      <e_t_con_1/>
      <e_t_abs>
        <el/>
        <e2/>
      </e_t_abs>
      <e_t_con_2/>
    </e_con>
    

    You will find that you receive the error you seek, such as this one produced by Xerces-J:

    [Error] try2.xml:5:12: cvc-type.2: The type definition cannot be abstract for element e_t_abs.