Catalog Common Resources





Item 47. Catalog Common Resources

Many XML processes use system IDs (in practice, URLs) to locate the standard DTDs, schemas, stylesheets, and other supporting files for applications like DocBook, XHTML, and SVG. However, this can put quite a load on the central server, and it means your application may have to wait on a potentially slow remote server you don't control. You might not even be able to process your documents when the central server is down due to hardware failure, a system crash, or network outages. Alternatively, you can use XML catalogs to remap public IDs and URLs. A catalog can convert public IDs like -//OASIS//DTD DocBook XML V4.2//EN into absolute URLs like http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd. It can replace remote URLs like http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd with local URLs like file:///home/elharo/docbook/docbookx.dtd. This offers fast, reliable access to the DTDs and schemas without making the documents less portable across systems and networks.

Catalogs provide the extra level of indirection that makes XML processing much more flexible. They allow Uniform Resource Names (URNs) to be used just as easily as URLs. Even if you're only using URLs, catalogs allow documents to be much more easily moved between systems. For instance, when I move the text of my manuscripts from my Linux desktop to my Windows laptop, I can change the location of the DTD just by editing one catalog file. I don't have to edit every chapter document separately to tell the XML parser and the XSLT processor where to find the right DTD.

Of course, not all requests have to (or should) go through a catalog. If the catalog doesn't have an entry for a particular public ID or URL, the parser can fall back to the original remote URL. For instance, it could load the XHTML DTD from the W3C web site. However, the parser needs to make a network connection only if the resource isn't available locally. This saves both processing time and network bandwidth.

You can even use catalogs to choose different stylesheets or schemas depending on your needs. For instance, by editing the catalog, you can test several different possible schemas or stylesheets to see which one you prefer. You might even choose between a stylesheet that generates HTML and one that generates XHTML.


     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows