6.2.2 Using the document’s URI to locate a schema

A ‘uri’ rule locates a schema based on the URI of the document. The ‘uri’ attribute specifies the URI of the schema. The ‘resource’ attribute can be used to specify the schema for a particular document. For example,

<uri resource="spec.xml" uri="docbook.rnc"/>

specifies that the schema for ‘spec.xml’ is ‘docbook.rnc’.

The ‘pattern’ attribute can be used instead of the ‘resource’ attribute to specify the schema for any document whose URI matches a pattern. The pattern has the same syntax as an absolute or relative URI except that the path component of the URI can use a ‘*’ character to stand for zero or more characters within a path segment (i.e., any character other ‘/’). Typically, the URI pattern looks like a relative URI, but, whereas a relative URI in the ‘resource’ attribute is resolved into a particular absolute URI using the base URI of the schema locating file, a relative URI pattern matches if it matches some number of complete path segments of the document’s URI ending with the last path segment of the document’s URI. For example,

<uri pattern="*.xsl" uri="xslt.rnc"/>

specifies that the schema for documents with a URI whose path ends with ‘.xsl’ is ‘xslt.rnc’.

A ‘transformURI’ rule locates a schema by transforming the URI of the document. The ‘fromPattern’ attribute specifies a URI pattern with the same meaning as the ‘pattern’ attribute of the ‘uri’ element. The ‘toPattern’ attribute is a URI pattern that is used to generate the URI of the schema. Each ‘*’ in the ‘toPattern’ is replaced by the string that matched the corresponding ‘*’ in the ‘fromPattern’. The resulting string is appended to the initial part of the document’s URI that was not explicitly matched by the ‘fromPattern’. The rule matches only if the transformed URI identifies an existing resource. For example, the rule

<transformURI fromPattern="*.xml" toPattern="*.rnc"/>

would transform the URI ‘file:///home/jjc/docs/spec.xml’ into the URI ‘file:///home/jjc/docs/spec.rnc’. Thus, this rule specifies that to locate a schema for a document ‘foo.xml’, Emacs should test whether a file ‘foo.rnc’ exists in the same directory as ‘foo.xml’, and, if so, should use it as the schema.