ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 5 / 8 << | Prev | Next |
Contents > Including > The wildcard "xsd:any" and inclusions

The wildcard "xsd:any" and inclusions

  1. Including document has non-null target namespaces, included null target namespace
XML Schema keys: include, any

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

When the target namespace of the included schema is null, it is changed to the target namespace of the including document. This process includes also the wildcards: "xsd:any" elements. In this example, the included schema allows one arbitrary element from target namespace, so after inclusion, the "##targetNamespace" will stand for "http://foo", not for null-namespace. Schema Representation Constraint: Inclusion Constraints and Semantics, 3.2.2 .

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:any namespace="##targetNamespace" minOccurs="1" maxOccurs="1" processContents="skip"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>