5.4 Namespaces

Schemas are reasonably well integrated with namespaces. The xs:schema element, for example, should normally have a targetNamespace attribute. It indicates the namespace in which the elements and attributes defined by the schema should appear. If no such attribute exists, the schema is intended for unqualified names perhaps to validate some XML designed before namespaces were recommended.

When a targetNamespace exists, that namespace must qualify all global elements and attributes. Local elements and attributes are a different matter, however. By default, they are unqualified and, in effect, get their namespace from their nearest global ancestor. But either or both of the elementForm-Default and attributeFormDefault attributes on the xs:schema element may be set to "qualified." Doing so requires that local elements or attributes, respectively, appear qualified with a namespace prefix bound to the targetNamespace. Any particular local element or attribute specification can override these defaults by using the "form" attribute on that specification with the value "qualified" or "unqualified" as appropriate.

The xs:include element provides a way to include parts of a schema that reside in different files. Within the content of xs:schema, you can say

 <xs:include schemaLocation="http://example.com/schemaPart.xsd"/> 

or something similar to include the schema content from that file as if it were present in the place of the xs:include element. You can include more than one file, and included files can themselves include other files.

The xs:redefine element is similar to include. However, as part of the body of an xs:redefine element, you can include specifications of types, elements, and so on that will override the particular components in the material being included.

Finally, you can use the xs:import element to input components from other namespaces. Each xs:import element must have a "namespace" attribute, which identifies the remote namespace of the components to be imported. It may also contain a schemaLocation attribute with a URI value to help in locating the remote schema. A normal xmlns attribute on the xs:schema element binds this remote namespace to a local prefix. Then, when components appear with that prefix, the schema will attempt to import that particular component from the remote schema. Although multiple xs:import elements may exist, they must be the first children of xs:schema, appearing before any other children.

Secure XML(c) The New Syntax for Signatures and Encryption
Secure XML: The New Syntax for Signatures and Encryption
ISBN: 0201756056
EAN: 2147483647
Year: 2005
Pages: 186

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net