Catalog Syntax

A catalog is just an XML document in the syntax defined by the OASIS XML Catalogs standard (http://www.oasis- open .org/ committees /entity/ specs /cs-entity-xml-catalogs-1.0.html). The root element of this document is catalog , which is in the urn:oasis: names :tc:entity:xmlns:xml:catalog namespace. The catalog element contains public elements that remap public IDs and system elements that remap system IDs. Example 47-1 shows a simple catalog that maps the public ID for DocBook to a file in the local file system.

Example 47-1 A Catalog Document
 <?xml version="1.0"?> <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">   <public publicId="-//OASIS//DTD DocBook XML V4.2//EN"           uri="file:///opt/xml/docbook/docbookx.dtd"/> </catalog> 

The public element maps the public ID -//OASIS//DTD DocBook XML V4.2//EN to the local URL file:///opt/xml/docbook/docbookx.dtd. The beginning of each chapter has the following document type declaration.

 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"     "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> 

Its system ID points to the remote DTD on the OASIS web site. However, that won't be used. The parser looks for the public ID in the local catalog.xml file. The parser then uses the URL from the catalog (if found) instead of the one in the document itself. However, if the catalog doesn't contain a mapping for the public ID, the parser will use the URL included in the document itself.

As mentioned above, you can also remap system IDs by using the system element. This is useful for loading content that doesn't have a public ID, such as stylesheets referenced by an xml-stylesheet processing instruction or multiple source documents loaded by the document() function in XSLT. For example, the system element shown next remaps the DocBook XSL stylesheet at SourceForge to a local copy stored in /opt/xml/docbook-xsl/.

 <system systemId= "http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"    uri="file:///opt/xml/docbook-xsl/html/docbook.xsl"/> 

The rewriteURI element can remap a whole set of URLs from a particular server. This is very much like the mod_rewrite module in the Apache web server. For example, the code below maps all the DocBook stylesheet URLs to a local directory on a UNIX box.

 <rewriteURI uriStartString=    "http://docbook.sourceforge.net/release/xsl/current/"    rewritePrefix="file:///opt/xml/docbook-xsl/" /> 

For various technical reasons, if you're remapping the URLs in DTD system identifiers, use a rewriteSystem element instead of a rewriteURI element.

 <rewriteSystem systemIdStartString=     "http://www.oasis-open.org/docbook/xml/4.2/"     rewritePrefix="/opt/xml/docbook/" /> 


Effective XML. 50 Specific Ways to Improve Your XML
Effective XML: 50 Specific Ways to Improve Your XML
ISBN: 0321150406
EAN: 2147483647
Year: 2002
Pages: 144

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