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
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" >

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:element name="b" type="b"/>

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

2. Relax NG

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

Valid document

<a xmlns="">

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" >

    <ref name="a"/>

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

  <define name="b">
    <element name="b">