Section 22.4.  Declaring schema conformance

Prev don't be afraid of buying books Next

22.4. Declaring schema conformance

How does an XML document tell a processor that it conforms to a particular XSDL schema definition? Usually it doesn't!

In theory, you can determine which schema definition to use from the root element type, file type, or other cues. In practice, the namespace is typically used.

There is a convention specified in the XML Schema specification to allow the document author to give a more explicit hint to the receiver. Example 22-11 demonstrates.

Example 22-11. Referring to a schema definition
 <myns:mydoc     xmlns:myns="http://www.myns.com/myns"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://www.myns.com/myns                         http://www.mysite.com/myxsdl.xsd"> </myns:mydoc> 

Note the declaration of the xsi namespace prefix. It identifies a namespace that is specifically for putting XML Schema information into instance documents. There is a global attribute in this namespace called schemaLocation that allows a document to point to an appropriate schema definition.

The attribute value is defined as a list of paired URIs. The first one in each pair is a namespace URI. The second one is the URI for a schema document. As the schema processor works its way through the instance document, it can find the applicable schema for an element or attribute by looking up its namespace.

The sender of a document may also provide the receiver with a schema through an API, command line, or graphical interface.

Although there is nothing wrong with using these hints just to check whether a document is valid, often you want to check whether it validates against some particular schema. In that case you don't want your software to use hints, you want it to use the schema you've provided.

The manner in which you tell the software what schema to use for a particular namespace will depend on the software. One convention is merely to configure the software with a list of schemas. The software can read the schemas and collect the list of target namespaces from the targetNamespace attributes. Then, when it sees a particular namespace in a document it can use the appropriate schema to validate it. Because you provide the list of schemas in the beginning, you know exactly what schemas are being used to validate no matter what is in the document.

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

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