ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 2 / 8 << | Prev | Next |
Contents > Substitutions > Attribute block

Attribute block

  1. XML Schema
XML Schema keys: block, substitutionGroup

1. XML Schema

The schema below defines an abstract element named "myAbstract" (attribute "abstract" is set to "true"). using the attribute "block" set to "substitution", we forbid all substitutions. I am not sure, if there can be any valid document :-).

Invalid document
Substitutions are forbidden, thus the document is not valid.


<root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <unchanged>7</unchanged>
</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="myAbstract"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="myAbstract" type="AAA" abstract="true" block="substitution"/>

  <xsd:simpleType name="AAA">
    <xsd:restriction base="xsd:integer">
      <xsd:minInclusive value="1"/>
      <xsd:maxInclusive value="9"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:element name="unchanged" substitutionGroup="myAbstract" type="AAA"/>
</xsd:schema>