catalog.html revision c6271d208e0dc8768aac1dd7c162ddef121fbaa3
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 2<html> 3<head> 4<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> 5<style type="text/css"><!-- 6TD {font-size: 10pt; font-family: Verdana,Arial,Helvetica} 7BODY {font-size: 10pt; font-family: Verdana,Arial,Helvetica; margin-top: 5pt; margin-left: 0pt; margin-right: 0pt} 8H1 {font-size: 16pt; font-family: Verdana,Arial,Helvetica} 9H2 {font-size: 14pt; font-family: Verdana,Arial,Helvetica} 10H3 {font-size: 12pt; font-family: Verdana,Arial,Helvetica} 11A:link, A:visited, A:active { text-decoration: underline } 12--></style> 13<title>Catalog support</title> 14</head> 15<body bgcolor="#8b7765" text="#000000" link="#000000" vlink="#000000"> 16<table border="0" width="100%" cellpadding="5" cellspacing="0" align="center"><tr> 17<td width="180"> 18<a href="http://www.gnome.org/"><img src="smallfootonly.gif" alt="Gnome Logo"></a><a href="http://www.w3.org/Status"><img src="w3c.png" alt="W3C Logo"></a><a href="http://www.redhat.com/"><img src="redhat.gif" alt="Red Hat Logo"></a> 19</td> 20<td><table border="0" width="90%" cellpadding="2" cellspacing="0" align="center" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#fffacd"><tr><td align="center"> 21<h1>The XML C library for Gnome</h1> 22<h2>Catalog support</h2> 23</td></tr></table></td></tr></table></td> 24</tr></table> 25<table border="0" cellpadding="4" cellspacing="0" width="100%" align="center"><tr><td bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr> 26<td valign="top" width="200" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td> 27<table width="100%" border="0" cellspacing="1" cellpadding="3"> 28<tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Main Menu</b></center></td></tr> 29<tr><td bgcolor="#fffacd"><ul style="margin-left: -2pt"> 30<li><a href="index.html">Home</a></li> 31<li><a href="intro.html">Introduction</a></li> 32<li><a href="FAQ.html">FAQ</a></li> 33<li><a href="docs.html">Documentation</a></li> 34<li><a href="bugs.html">Reporting bugs and getting help</a></li> 35<li><a href="help.html">How to help</a></li> 36<li><a href="downloads.html">Downloads</a></li> 37<li><a href="news.html">News</a></li> 38<li><a href="XML.html">XML</a></li> 39<li><a href="XSLT.html">XSLT</a></li> 40<li><a href="architecture.html">libxml architecture</a></li> 41<li><a href="tree.html">The tree output</a></li> 42<li><a href="interface.html">The SAX interface</a></li> 43<li><a href="xmldtd.html">Validation & DTDs</a></li> 44<li><a href="xmlmem.html">Memory Management</a></li> 45<li><a href="encoding.html">Encodings support</a></li> 46<li><a href="xmlio.html">I/O Interfaces</a></li> 47<li><a href="catalog.html">Catalog support</a></li> 48<li><a href="library.html">The parser interfaces</a></li> 49<li><a href="entities.html">Entities or no entities</a></li> 50<li><a href="namespaces.html">Namespaces</a></li> 51<li><a href="upgrade.html">Upgrading 1.x code</a></li> 52<li><a href="DOM.html">DOM Principles</a></li> 53<li><a href="example.html">A real example</a></li> 54<li><a href="contribs.html">Contributions</a></li> 55<li> 56<a href="xml.html">flat page</a>, <a href="site.xsl">stylesheet</a> 57</li> 58</ul></td></tr> 59</table> 60<table width="100%" border="0" cellspacing="1" cellpadding="3"> 61<tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Related links</b></center></td></tr> 62<tr><td bgcolor="#fffacd"><ul style="margin-left: -2pt"> 63<li><a href="http://mail.gnome.org/archives/xml/">Mail archive</a></li> 64<li><a href="http://xmlsoft.org/XSLT/">XSLT libxslt</a></li> 65<li><a href="http://www.cs.unibo.it/~casarini/gdome2/">DOM gdome2</a></li> 66<li><a href="ftp://xmlsoft.org/">FTP</a></li> 67<li><a href="http://www.fh-frankfurt.de/~igor/projects/libxml/">Windows binaries</a></li> 68<li><a href="http://pages.eidosnet.co.uk/~garypen/libxml/">Solaris binaries</a></li> 69<li><a href="http://bugzilla.gnome.org/buglist.cgi?product=libxml">Bug Tracker</a></li> 70</ul></td></tr> 71</table> 72</td></tr></table></td> 73<td valign="top" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%"><tr><td><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table border="0" cellpadding="3" cellspacing="1" width="100%"><tr><td bgcolor="#fffacd"> 74<p>Table of Content:</p> 75<ol> 76<li><a href="General2">General overview</a></li> 77<li><a href="#definition">The definition</a></li> 78<li><a href="#Simple">Using catalogs</a></li> 79<li><a href="#Some">Some examples</a></li> 80<li><a href="#reference">How to tune catalog usage</a></li> 81<li><a href="#validate">How to debug catalog processing</a></li> 82<li><a href="#Declaring">How to create and maintain catalogs</a></li> 83<li><a href="#implemento">The implementor corner quick review of the 84 API</a></li> 85<li><a href="#Other">Other resources</a></li> 86</ol> 87<h3><a name="General2">General overview</a></h3> 88<p>What is a catalog? Basically it's a lookup mechanism used when an entity 89(a file or a remote resource) references another entity. The catalog lookup 90is inserted between the moment the reference is recognized by the software 91(XML parser, stylesheet processing, or even images referenced for inclusion 92in a rendering) and the time where loading that resource is actually 93started.</p> 94<p>It is basically used for 3 things:</p> 95<ul> 96<li>mapping from "logical" names, the public identifiers and a more 97 concrete name usable for download (and URI). For example it can associate 98 the logical name 99 <p>"-//OASIS//DTD DocBook XML V4.1.2//EN"</p> 100<p>of the DocBook 4.1.2 XML DTD with the actual URL where it can be 101 downloaded</p> 102<p>http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd</p> 103</li> 104<li>remapping from a given URL to another one, like an HTTP indirection 105 saying that 106 <p>"http://www.oasis-open.org/committes/tr.xsl"</p> 107<p>should really be looked at</p> 108<p>"http://www.oasis-open.org/committes/entity/stylesheets/base/tr.xsl"</p> 109</li> 110<li>providing a local cache mechanism allowing to load the entities 111 associated to public identifiers or remote resources, this is a really 112 important feature for any significant deployment of XML or SGML since it 113 allows to avoid the aleas and delays associated to fetching remote 114 resources.</li> 115</ul> 116<h3><a name="definition">The definitions</a></h3> 117<p>Libxml, as of 2.4.3 implements 2 kind of catalogs:</p> 118<ul> 119<li>the older SGML catalogs, the official spec is SGML Open Technical 120 Resolution TR9401:1997, but is better understood by reading <a href="http://www.jclark.com/sp/catalog.htm">the SP Catalog page</a> from 121 James Clark. This is relatively old and not the preferred mode of 122 operation of libxml.</li> 123<li> 124<a href="http://www.oasis-open.org/committees/entity/spec.html">XML 125 Catalogs</a> 126 is far more flexible, more recent, uses an XML syntax and should scale 127 quite better. This is the default option of libxml.</li> 128</ul> 129<p> 130<h3><a name="Simple">Using catalog</a></h3> 131<p>In a normal environment libxml will by default check the presence of a 132catalog in /etc/xml/catalog, and assuming it has been correctly populated, 133the processing is completely transparent to the document user. To take a 134concrete example, suppose you are authoring a DocBook document, this one 135starts with the following DOCTYPE definition:</p> 136<pre><?xml version='1.0'?> 137<!DOCTYPE book PUBLIC "-//Norman Walsh//DTD DocBk XML V3.1.4//EN" 138 "http://nwalsh.com/docbook/xml/3.1.4/db3xml.dtd"></pre> 139<p>When validating the document with libxml, the catalog will be 140automatically consulted to lookup the public identifier "-//Norman Walsh//DTD 141DocBk XML V3.1.4//EN" and the system identifier 142"http://nwalsh.com/docbook/xml/3.1.4/db3xml.dtd", and if these entities have 143been installed on your system and the catalogs actually point to them, libxml 144will fetch them from the local disk.</p> 145<p style="font-size: 10pt"> 146<strong>Note</strong>: Really don't use this 147DOCTYPE example it's a really old version, but is fine as an example.</p> 148<p>Libxml will check the catalog each time that it is requested to load an 149entity, this includes DTD, external parsed entities, stylesheets, etc ... If 150your system is correctly configured all the authoring phase and processing 151should use only local files, even if your document stays portable because it 152uses the canonical public and system ID, referencing the remote document.</p> 153<h3><a name="Some">Some examples:</a></h3> 154<p>Here is a couple of fragments from XML Catalogs used in libxml early 155regression tests in <code>test/catalogs</code> :</p> 156<pre><?xml version="1.0"?> 157<!DOCTYPE catalog PUBLIC 158 "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" 159 "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> 160<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> 161 <public publicId="-//OASIS//DTD DocBook XML V4.1.2//EN" 162 uri="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"/> 163...</pre> 164<p>This is the beginning of a catalog for DocBook 4.1.2, XML Catalogs are 165written in XML, there is a specific namespace for catalog elements 166"urn:oasis:names:tc:entity:xmlns:xml:catalog". The first entry in this 167catalog is a <code>public</code> mapping it allows to associate a Public 168Identifier with an URI.</p> 169<pre>... 170 <rewriteSystem systemIdStartString="http://www.oasis-open.org/docbook/" 171 rewritePrefix="file:///usr/share/xml/docbook/"/> 172...</pre> 173<p>A <code>rewriteSystem</code> is a very powerful instruction, it says that 174any URI starting with a given prefix should be looked at another URI 175constructed by replacing the prefix with an new one. In effect this acts like 176a cache system for a full area of the Web. In practice it is extremely useful 177with a file prefix if you have installed a copy of those resources on your 178local system.</p> 179<pre>... 180<delegatePublic publicIdStartString="-//OASIS//DTD XML Catalog //" 181 catalog="file:///usr/share/xml/docbook.xml"/> 182<delegatePublic publicIdStartString="-//OASIS//ENTITIES DocBook XML" 183 catalog="file:///usr/share/xml/docbook.xml"/> 184<delegatePublic publicIdStartString="-//OASIS//DTD DocBook XML" 185 catalog="file:///usr/share/xml/docbook.xml"/> 186<delegateSystem systemIdStartString="http://www.oasis-open.org/docbook/" 187 catalog="file:///usr/share/xml/docbook.xml"/> 188<delegateURI uriStartString="http://www.oasis-open.org/docbook/" 189 catalog="file:///usr/share/xml/docbook.xml"/> 190...</pre> 191<p>Delegation is the core features which allows to build a tree of catalogs, 192easier to maintain than a single catalog, based on Public Identifier, System 193Identifier or URI prefixes it instructs the catalog software to look up 194entries in another resource. This feature allow to build hierarchies of 195catalogs, the set of entries presented should be sufficient to redirect the 196resolution of all DocBook references to the specific catalog in 197<code>/usr/share/xml/docbook.xml</code> this one in turn could delegate all 198references for DocBook 4.2.1 to a specific catalog installed at the same time 199as the DocBook resources on the local machine.</p> 200<h3><a name="reference">How to tune catalog usage:</a></h3> 201<p>The user can change the default catalog behaviour by redirecting queries 202to its own set of catalogs, this can be done by setting the 203<code>XML_CATALOG_FILES</code> environment variable to a list of catalogs, an 204empty one should deactivate loading the default <code>/etc/xml/catalog</code> 205default catalog</p> 206<h3><a name="validate">How to debug catalog processing:</a></h3> 207<p>Setting up the <code>XML_DEBUG_CATALOG</code> environment variable will 208make libxml output debugging informations for each catalog operations, for 209example:</p> 210<pre>orchis:~/XML -> xmllint --memory --noout test/ent2 211warning: failed to load external entity "title.xml" 212orchis:~/XML -> export XML_DEBUG_CATALOG= 213orchis:~/XML -> xmllint --memory --noout test/ent2 214Failed to parse catalog /etc/xml/catalog 215Failed to parse catalog /etc/xml/catalog 216warning: failed to load external entity "title.xml" 217Catalogs cleanup 218orchis:~/XML -> </pre> 219<p>The test/ent2 references an entity, running the parser from memory makes 220the base URI unavailable and the the "title.xml" entity cannot be loaded. 221Setting up the debug environment variable allows to detect that an attempt is 222made to load the <code>/etc/xml/catalog</code> but since it's not present the 223resolution fails.</p> 224<p>But the most advanced way to debug XML catalog processing is to use the 225<strong>xmlcatalog</strong> command shipped with libxml2, it allows to load 226catalogs and make resolution queries to see what is going on. This is also 227used for the regression tests:</p> 228<pre>orchis:~/XML -> /xmlcatalog test/catalogs/docbook.xml \ 229 "-//OASIS//DTD DocBook XML V4.1.2//EN" 230http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd 231orchis:~/XML -> </pre> 232<p>For debugging what is going on, adding one -v flags increase the verbosity 233level to indicate the processing done (adding a second flag also indicate 234what elements are recognized at parsing):</p> 235<pre>orchis:~/XML -> /xmlcatalog -v test/catalogs/docbook.xml \ 236 "-//OASIS//DTD DocBook XML V4.1.2//EN" 237Parsing catalog test/catalogs/docbook.xml's content 238Found public match -//OASIS//DTD DocBook XML V4.1.2//EN 239http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd 240Catalogs cleanup 241orchis:~/XML -> </pre> 242<p>A shell interface is also available to debug and process multiple queries 243(and for regression tests):</p> 244<pre>orchis:~/XML -> /xmlcatalog -shell test/catalogs/docbook.xml \ 245 "-//OASIS//DTD DocBook XML V4.1.2//EN" 246> help 247Commands available: 248public PublicID: make a PUBLIC identifier lookup 249system SystemID: make a SYSTEM identifier lookup 250resolve PublicID SystemID: do a full resolver lookup 251add 'type' 'orig' 'replace' : add an entry 252del 'values' : remove values 253dump: print the current catalog state 254debug: increase the verbosity level 255quiet: decrease the verbosity level 256exit: quit the shell 257> public "-//OASIS//DTD DocBook XML V4.1.2//EN" 258http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd 259> quit 260orchis:~/XML -> </pre> 261<p>This should be sufficient for most debugging purpose, this was actually 262used heavily to debug the XML Catalog implementation itself.</p> 263<h3> 264<a name="Declaring">How to create and maintain</a> catalogs:</h3> 265<p>Basically XML Catalogs are XML files, you can either use XML tools to 266manage them or use <strong>xmlcatalog</strong> for this. The basic step is 267to create a catalog the -create option provide this facility:</p> 268<pre>orchis:~/XML -> /xmlcatalog --create tst.xml 269<?xml version="1.0"?> 270<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" 271 "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> 272<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"/> 273orchis:~/XML -> </pre> 274<p>By default xmlcatalog does not overwrite the original catalog and save the 275result on the standard output, this can be overridden using the -noout 276option. The <code>-add</code> command allows to add entries in the 277catalog:</p> 278<pre>orchis:~/XML -> /xmlcatalog --noout --create --add "public" \ 279 "-//OASIS//DTD DocBook XML V4.1.2//EN" \ 280 http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd tst.xml 281orchis:~/XML -> cat tst.xml 282<?xml version="1.0"?> 283<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" \ 284 "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> 285<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> 286<public publicId="-//OASIS//DTD DocBook XML V4.1.2//EN" 287 uri="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"/> 288</catalog> 289orchis:~/XML -> </pre> 290<p>The <code>-add</code> option will always take 3 parameters even if some of 291the XML Catalog constructs (like nextCatalog) will have only a single 292argument, just pass a third empty string, it will be ignored.</p> 293<p>Similarly the <code>-del</code> option remove matching entries from the 294catalog:</p> 295<pre>orchis:~/XML -> /xmlcatalog --del \ 296 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" tst.xml 297<?xml version="1.0"?> 298<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" 299 "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> 300<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"/> 301orchis:~/XML -> </pre> 302<p>The catalog is now empty. Note that the matching of <code>-del</code> is 303exact and would have worked in a similar fashion with the Public ID 304string.</p> 305<p>This is rudimentary but should be sufficient to manage a not too complex 306catalog tree of resources.</p> 307<h3><a name="implemento">The implementor corner quick review of the 308API:</a></h3> 309<p>First, and like for every other module of libxml, there is an 310automatically generated <a href="html/libxml-catalog.html">API page for 311catalog support</a>.</p> 312<p>The header for the catalog interfaces should be included as:</p> 313<pre>#include <libxml/catalog.h></pre> 314<p>The API is voluntarily kept very simple. First it is not obvious that 315applications really need access to it since it is the default behaviour of 316libxml (Note: it is possible to completely override libxml default catalog by 317using <a href="html/libxml-parser.html">xmlSetExternalEntityLoader</a> to 318plug an application specific resolver).</p> 319<p>Basically libxml support 2 catalog lists:</p> 320<ul> 321<li>the default one, global shared by all the application</li> 322<li>a per-document catalog, this one is built if the document uses the 323 <code>oasis-xml-catalog</code> PIs to specify its own catalog list, it is 324 associated to the parser context and destroyed when the parsing context 325 is destroyed.</li> 326</ul> 327<p>the document one will be used first if it exists.</p> 328<h4>Initialization routines:</h4> 329<p>xmlInitializeCatalog(), xmlLoadCatalog() and xmlLoadCatalogs() should be 330used at startup to initialize the catalog, if the catalog should be 331initialized with specific values xmlLoadCatalog() or xmlLoadCatalogs() 332should be called before xmlInitializeCatalog() which would otherwise do a 333default initialization first.</p> 334<p>The xmlCatalogAddLocal() call is used by the parser to grow the document 335own catalog list if needed.</p> 336<h4>Preferences setup:</h4> 337<p>The XML Catalog spec requires the possibility to select default 338preferences between public and system delegation, 339xmlCatalogSetDefaultPrefer() allows this, xmlCatalogSetDefaults() and 340xmlCatalogGetDefaults() allow to control if XML Catalogs resolution should 341be forbidden, allowed for global catalog, for document catalog or both, the 342default is to allow both.</p> 343<p>And of course xmlCatalogSetDebug() allows to generate debug messages 344(through the xmlGenericError() mechanism).</p> 345<h4>Querying routines:</h4> 346<p>xmlCatalogResolve(), xmlCatalogResolveSystem(), xmlCatalogResolvePublic() 347and xmlCatalogResolveURI() are relatively explicit if you read the XML 348Catalog specification they correspond to section 7 algorithms, they should 349also work if you have loaded an SGML catalog with a simplified semantic.</p> 350<p>xmlCatalogLocalResolve() and xmlCatalogLocalResolveURI() are the same but 351operate on the document catalog list</p> 352<h4>Cleanup and Miscellaneous:</h4> 353<p>xmlCatalogCleanup() free-up the global catalog, xmlCatalogFreeLocal() is 354the per-document equivalent.</p> 355<p>xmlCatalogAdd() and xmlCatalogRemove() are used to dynamically modify the 356first catalog in the global list, and xmlCatalogDump() allows to dump a 357catalog state, those routines are primarily designed for xmlcatalog, I'm not 358sure that exposing more complex interfaces (like navigation ones) would be 359really useful.</p> 360<p>The xmlParseCatalogFile() is a function used to load XML Catalog files, 361it's similar as xmlParseFile() except it bypass all catalog lookups, it's 362provided because this functionality may be useful for client tools.</p> 363<h4>threaded environments:</h4> 364<p>Since the catalog tree is built progressively, some care has been taken to 365try to avoid troubles in multithreaded environments. The code is now thread 366safe assuming that the libxml library has been compiled with threads 367support.</p> 368<p> 369<h3><a name="Other">Other resources</a></h3> 370<p>The XML Catalog specification is relatively recent so there isn't much 371literature to point at:</p> 372<ul> 373<li>You can find an good rant from Norm Walsh about <a href="http://www.arbortext.com/Think_Tank/XML_Resources/Issue_Three/issue_three.html">the 374 need for catalogs</a>, it provides a lot of context informations even if 375 I don't agree with everything presented.</li> 376<li>An <a href="http://home.ccil.org/~cowan/XML/XCatalog.html">old XML 377 catalog proposal</a> from John Cowan</li> 378<li>The <a href="http://www.rddl.org/">Resource Directory Description 379 Language</a> (RDDL) another catalog system but more oriented toward 380 providing metadata for XML namespaces.</li> 381<li>the page from the OASIS Technical <a href="http://www.oasis-open.org/committees/entity/">Committee on Entity 382 Resolution</a> who maintains XML Catalog, you will find pointers to the 383 specification update, some background and pointers to others tools 384 providing XML Catalog support</li> 385<li>I have uploaded <a href="ftp://xmlsoft.org/test/dbk412catalog.tar.gz">a 386 mall tarball</a> containing XML Catalogs for DocBook 4.1.2 which seems to 387 work fine for me</li> 388<li>The <a href="http://www.xmlsoft.org/xmlcatalog_man.html">xmlcatalog 389 manual page</a> 390</li> 391</ul> 392<p>If you have suggestions for corrections or additions, simply contact 393me:</p> 394<p><a href="mailto:daniel@veillard.com">Daniel Veillard</a></p> 395</td></tr></table></td></tr></table></td></tr></table></td> 396</tr></table></td></tr></table> 397</body> 398</html> 399