ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 3 / 4 << | Prev | Next |
Contents > Naming and definitions > Element and type have the same name

Element and type have the same name

  1. XML Schema
  2. Relax NG

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

XML Schema keys: type, name
Relax NG keys: name

1. XML Schema

There is no name clash, because the elements and types are in different "symbol space". In other words, you can name your element "b" and some simpleType "b" too at the same time.

Valid document


<a xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <b>xx</b>
</a>

Correct XML Schema (correct_0.xsd)
There is no name mismatch, because names of elements are from other "symbol space" than types.


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

  <xsd:element name="a" type="a"/>

  <xsd:complexType name="a">
    <xsd:sequence>
      <xsd:element name="b" type="b"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:simpleType name="b">
    <xsd:restriction base="xsd:string"/>
  </xsd:simpleType>
</xsd:schema>

2. Relax NG

In Relax NG, there is no clash among the names of elements, attributes and patterns.

Valid document


<a xmlns="">
  <b>xx</b>
</a>

Correct Relax NG schema (correctRelax_0.rng)


<grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" ns="" xmlns="http://relaxng.org/ns/structure/1.0" >

  <start>
    <ref name="a"/>
  </start>

  <define name="a">
    <element name="a">
      <ref name="b"/>
    </element>
  </define>

  <define name="b">
    <element name="b">
      <text/>
    </element>
  </define>
</grammar>