ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 2 / 4 << | Prev | Next |
Contents > Importing and combining multiple schemas > Importing schema and processContents "lax"

Importing schema and processContents "lax"

  1. XML Schema

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

XML Schema keys: import, processContents

1. XML Schema

Let's say we use "any" or "anyAttribute" elements and set their attribute "processContents" to value "lax". Then those elements/attributes, which are represented by the "any/anyAttribute" pattern are validated as follows: if there is a definition for them, they must be valid with respect to that definition. If there is no definition, never mind. 3.10.1 The Wildcard Schema Component

Valid document
The file is valid, the "bar:x" elements are validated against their definition in file "correct_1.xsd".


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

Valid document
This document is valid too, because the "processContents" attribute in schema is set to "lax" and thus it does not matter, that there is no definition for element "x" from null namespace. (We have provided only definitions for element "bar:x".)


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

Invalid document
The "processContents" is set to "lax", but there is a definition for "bar:x" element (in file "correct_1.xsd"), so this element must be valid with respect to this definition - it must contain an integer (and "aaa" does not represent an integer).


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

Correct XML Schema (correct_0.xsd)


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

  <xsd:import namespace="http://bar" schemaLocation="correct_1.xsd"/>

  <xsd:element name="root">
    <xsd:complexType>
      <xsd:sequence minOccurs="1" maxOccurs="1">
        <xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

Correct XML Schema (correct_1.xsd)


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

  <xsd:element name="x" type="xsd:integer"/>
</xsd:schema>