ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 3 / 8 << | Prev | Next |
Contents > Including > Including document has non-null target namespaces, included null target namespace

Including document has non-null target namespaces, included null target namespace

  1. form is "qualified"
  2. form is "unqualified"

1. form is "qualified"

Because the included schema does not have targetNamespace attribute and the form is "qualified", the target namespace will be "inherited" from the including schema. Schema Representation Constraint: Inclusion Constraints and Semantics, 2.3 .

Valid document


<foo:root xsi:schemaLocation="http://foo correct_0.xsd" xmlns:foo="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <foo:x>dhhglh</foo:x>
</foo:root>

Invalid document


<foo:root xsi:schemaLocation="http://foo correct_0.xsd" xmlns:foo="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <x xmlns="">dhhglh</x>
</foo:root>

Correct XML Schema (correct_0.xsd)


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

  <xsd:include schemaLocation="correct_1.xsd"/>

  <xsd:element name="root" type="foo:myType"/>
</xsd:schema>

Correct XML Schema (correct_1.xsd)
Notice, here is no "targetNamespace" attribute.


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

  <xsd:complexType name="myType">
    <xsd:sequence>
      <xsd:element name="x" minOccurs="1" maxOccurs="1" type="xsd:string" form="qualified"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

2. form is "unqualified"

Invalid document
This is the default behaviour.


<foo:root xsi:schemaLocation="http://foo correct_0.xsd" xmlns:foo="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <foo:x>dhhglh</foo:x>
</foo:root>

Valid document


<foo:root xsi:schemaLocation="http://foo correct_0.xsd" xmlns:foo="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <x xmlns="">dhhglh</x>
</foo:root>

Correct XML Schema (correct_0.xsd)


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

  <xsd:include schemaLocation="correct_1.xsd"/>

  <xsd:element name="root" type="foo:myType"/>
</xsd:schema>

Correct XML Schema (correct_1.xsd)
Notice, here is no "targetNamespace" attribute.


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

  <xsd:complexType name="myType">
    <xsd:sequence>
      <xsd:element name="x" minOccurs="1" maxOccurs="1" type="xsd:string" form="unqualified"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>