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

The wildcard "xsd:anyAttribute" 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:anyAtribute" elements. In this example, the included schema allows one arbitrary attribute from namespace other than target namespace, so after inclusion, the "##other" will forbid attributes from both null-namespace and "http://foo" namespace. Schema Representation Constraint: Inclusion Constraints and Semantics, 3.2.2 .

Valid document


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

Invalid document
The attribute from null namespace is not allowed.


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

Invalid document
The attribute from namespace "http://foo" is not allowed.


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

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:anyAttribute namespace="##other" processContents="skip"/>
  </xsd:complexType>
</xsd:schema>