ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 3 / 8 << | Prev | Next |
Contents > Substitutions > Attribute block set to "restriction"

Attribute block set to "restriction"

  1. XML Schema

Please, send all comments, bug-reports, and contributions to Jiri.Jirat@systinet.com. Thank you very much.

XML Schema keys: block

1. XML Schema

The schema below defines three elements: "C", "D", "E". The elements "D" and "E" have the attribute "substitutionGroup" set to "C" (so they should be able to substitute the element "C"). But only element "E" can, because the type of element "D" is derived by a restriction from the type "AAA" and this would be in conflict with the "block" attribute of element "C" (it has value "restriction"). 3.3.6 Constraints on Element Declaration Schema Components; Schema Component Constraint: Substitution Group OK (Transitive)

Valid document


<root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <C>5</C>
</root>

Invalid document
Because the type of the element "D" is created by a restriction from type "AAA" and "AAA" is the type of "C" element and "C" element is defined with attribute "block" set to "restriction", the document is not valid.


<root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <D>7</D>
</root>

Valid document
Document is valid, because the type of the "E" element is not created by a restriction from the type "AAA" and substitutions are allowed.


<root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <E>2</E>
</root>

Correct XML Schema (correct_0.xsd)


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

  <xsd:element name="root">
    <xsd:complexType>
      <xsd:sequence minOccurs="1">
        <xsd:element ref="C"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:complexType name="AAA">
    <xsd:simpleContent>
      <xsd:extension base="xsd:integer"/>
    </xsd:simpleContent>
  </xsd:complexType>

  <xsd:element name="C" type="AAA" block="restriction"/>

  <xsd:element name="D" substitutionGroup="C">
    <xsd:complexType>
      <xsd:simpleContent>
        <xsd:restriction base="AAA">
          <xsd:minInclusive value="1"/>
          <xsd:maxInclusive value="8"/>
        </xsd:restriction>
      </xsd:simpleContent>
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="E" type="AAA" substitutionGroup="C"/>
</xsd:schema>