Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><link rel="SHORTCUT ICON" href="/favicon.ico" /><style type="text/css"> |
Daniel Veillard | 373a475 | 2002-02-21 14:46:29 +0000 | [diff] [blame] | 4 | TD {font-family: Verdana,Arial,Helvetica} |
| 5 | BODY {font-family: Verdana,Arial,Helvetica; margin-top: 2em; margin-left: 0em; margin-right: 0em} |
| 6 | H1 {font-family: Verdana,Arial,Helvetica} |
| 7 | H2 {font-family: Verdana,Arial,Helvetica} |
| 8 | H3 {font-family: Verdana,Arial,Helvetica} |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 9 | A:link, A:visited, A:active { text-decoration: underline } |
Daniel Veillard | b9ded82 | 2004-08-14 13:53:13 +0000 | [diff] [blame^] | 10 | </style><title>Catalog support</title></head><body bgcolor="#8b7765" text="#000000" link="#a06060" vlink="#a06060"><table border="0" width="100%" cellpadding="5" cellspacing="0" align="center"><tr><td width="120"><a href="http://swpat.ffii.org/"><img src="epatents.png" alt="Action against software patents" /></a></td><td width="180"><a href="http://www.gnome.org/"><img src="gnome2.png" alt="Gnome2 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><div align="left"><a href="http://xmlsoft.org/"><img src="Libxml2-Logo-180x168.gif" alt="Made with Libxml2 Logo" /></a></div></td><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"><h1>The XML C parser and toolkit of Gnome</h1><h2>Catalog support</h2></td></tr></table></td></tr></table></td></tr></table><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><td valign="top" width="200" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Main Menu</b></center></td></tr><tr><td bgcolor="#fffacd"><form action="search.php" enctype="application/x-www-form-urlencoded" method="get"><input name="query" type="text" size="20" value="" /><input name="submit" type="submit" value="Search ..." /></form><ul><li><a href="index.html">Home</a></li><li><a href="intro.html">Introduction</a></li><li><a href="FAQ.html">FAQ</a></li><li><a href="docs.html" style="font-weight:bold">Developer Menu</a></li><li><a href="bugs.html">Reporting bugs and getting help</a></li><li><a href="help.html">How to help</a></li><li><a href="downloads.html">Downloads</a></li><li><a href="news.html">News</a></li><li><a href="XMLinfo.html">XML</a></li><li><a href="XSLT.html">XSLT</a></li><li><a href="xmldtd.html">Validation & DTDs</a></li><li><a href="encoding.html">Encodings support</a></li><li><a href="catalog.html">Catalog support</a></li><li><a href="namespaces.html">Namespaces</a></li><li><a href="contribs.html">Contributions</a></li><li><a href="examples/index.html" style="font-weight:bold">Code Examples</a></li><li><a href="html/index.html" style="font-weight:bold">API Menu</a></li><li><a href="guidelines.html">XML Guidelines</a></li><li><a href="ChangeLog.html">ChangeLog</a></li></ul></td></tr></table><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Related links</b></center></td></tr><tr><td bgcolor="#fffacd"><ul><li><a href="http://mail.gnome.org/archives/xml/">Mail archive</a></li><li><a href="http://xmlsoft.org/XSLT/">XSLT libxslt</a></li><li><a href="http://phd.cs.unibo.it/gdome2/">DOM gdome2</a></li><li><a href="http://www.aleksey.com/xmlsec/">XML-DSig xmlsec</a></li><li><a href="ftp://xmlsoft.org/">FTP</a></li><li><a href="http://www.zlatkovic.com/projects/libxml/">Windows binaries</a></li><li><a href="http://garypennington.net/libxml2/">Solaris binaries</a></li><li><a href="http://www.zveno.com/open_source/libxml2xslt.html">MacOsX binaries</a></li><li><a href="http://sourceforge.net/projects/libxml2-pas/">Pascal bindings</a></li><li><a href="http://bugzilla.gnome.org/buglist.cgi?product=libxml2">Bug Tracker</a></li></ul></td></tr></table></td></tr></table></td><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"><p>Table of Content:</p><ol><li><a href="General2">General overview</a></li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 11 | <li><a href="#definition">The definition</a></li> |
| 12 | <li><a href="#Simple">Using catalogs</a></li> |
| 13 | <li><a href="#Some">Some examples</a></li> |
| 14 | <li><a href="#reference">How to tune catalog usage</a></li> |
| 15 | <li><a href="#validate">How to debug catalog processing</a></li> |
| 16 | <li><a href="#Declaring">How to create and maintain catalogs</a></li> |
| 17 | <li><a href="#implemento">The implementor corner quick review of the |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 18 | API</a></li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 19 | <li><a href="#Other">Other resources</a></li> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 20 | </ol><h3><a name="General2" id="General2">General overview</a></h3><p>What is a catalog? Basically it's a lookup mechanism used when an entity |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 21 | (a file or a remote resource) references another entity. The catalog lookup |
| 22 | is inserted between the moment the reference is recognized by the software |
| 23 | (XML parser, stylesheet processing, or even images referenced for inclusion |
| 24 | in a rendering) and the time where loading that resource is actually |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 25 | started.</p><p>It is basically used for 3 things:</p><ul><li>mapping from "logical" names, the public identifiers and a more |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 26 | concrete name usable for download (and URI). For example it can associate |
Daniel Veillard | ffb120d | 2001-08-23 00:52:23 +0000 | [diff] [blame] | 27 | the logical name |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 28 | <p>"-//OASIS//DTD DocBook XML V4.1.2//EN"</p> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 29 | <p>of the DocBook 4.1.2 XML DTD with the actual URL where it can be |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 30 | downloaded</p> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 31 | <p>http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd</p> |
| 32 | </li> |
| 33 | <li>remapping from a given URL to another one, like an HTTP indirection |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 34 | saying that |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 35 | <p>"http://www.oasis-open.org/committes/tr.xsl"</p> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 36 | <p>should really be looked at</p> |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 37 | <p>"http://www.oasis-open.org/committes/entity/stylesheets/base/tr.xsl"</p> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 38 | </li> |
| 39 | <li>providing a local cache mechanism allowing to load the entities |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 40 | associated to public identifiers or remote resources, this is a really |
| 41 | important feature for any significant deployment of XML or SGML since it |
MDT 2001 John Fleck | 0468500 | 2001-09-03 16:11:47 +0000 | [diff] [blame] | 42 | allows to avoid the aleas and delays associated to fetching remote |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 43 | resources.</li> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 44 | </ul><h3><a name="definition" id="definition">The definitions</a></h3><p>Libxml, as of 2.4.3 implements 2 kind of catalogs:</p><ul><li>the older SGML catalogs, the official spec is SGML Open Technical |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 45 | Resolution TR9401:1997, but is better understood by reading <a href="http://www.jclark.com/sp/catalog.htm">the SP Catalog page</a> from |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 46 | James Clark. This is relatively old and not the preferred mode of |
| 47 | operation of libxml.</li> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 48 | <li><a href="http://www.oasis-open.org/committees/entity/spec.html">XML |
Daniel Veillard | af43f63 | 2002-03-08 15:05:20 +0000 | [diff] [blame] | 49 | Catalogs</a> is far more flexible, more recent, uses an XML syntax and |
| 50 | should scale quite better. This is the default option of libxml.</li> |
Daniel Veillard | 8a46917 | 2003-06-12 16:05:07 +0000 | [diff] [blame] | 51 | </ul><p></p><h3><a name="Simple" id="Simple">Using catalog</a></h3><p>In a normal environment libxml2 will by default check the presence of a |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 52 | catalog in /etc/xml/catalog, and assuming it has been correctly populated, |
| 53 | the processing is completely transparent to the document user. To take a |
| 54 | concrete example, suppose you are authoring a DocBook document, this one |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 55 | starts with the following DOCTYPE definition:</p><pre><?xml version='1.0'?> |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 56 | <!DOCTYPE book PUBLIC "-//Norman Walsh//DTD DocBk XML V3.1.4//EN" |
| 57 | "http://nwalsh.com/docbook/xml/3.1.4/db3xml.dtd"></pre><p>When validating the document with libxml, the catalog will be |
| 58 | automatically consulted to lookup the public identifier "-//Norman Walsh//DTD |
| 59 | DocBk XML V3.1.4//EN" and the system identifier |
| 60 | "http://nwalsh.com/docbook/xml/3.1.4/db3xml.dtd", and if these entities have |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 61 | been installed on your system and the catalogs actually point to them, libxml |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 62 | will fetch them from the local disk.</p><p style="font-size: 10pt"><strong>Note</strong>: Really don't use this |
Daniel Veillard | 8a46917 | 2003-06-12 16:05:07 +0000 | [diff] [blame] | 63 | DOCTYPE example it's a really old version, but is fine as an example.</p><p>Libxml2 will check the catalog each time that it is requested to load an |
MDT 2001 John Fleck | 0468500 | 2001-09-03 16:11:47 +0000 | [diff] [blame] | 64 | entity, this includes DTD, external parsed entities, stylesheets, etc ... If |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 65 | your system is correctly configured all the authoring phase and processing |
MDT 2001 John Fleck | 0468500 | 2001-09-03 16:11:47 +0000 | [diff] [blame] | 66 | should use only local files, even if your document stays portable because it |
Daniel Veillard | 8a46917 | 2003-06-12 16:05:07 +0000 | [diff] [blame] | 67 | uses the canonical public and system ID, referencing the remote document.</p><h3><a name="Some" id="Some">Some examples:</a></h3><p>Here is a couple of fragments from XML Catalogs used in libxml2 early |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 68 | regression tests in <code>test/catalogs</code> :</p><pre><?xml version="1.0"?> |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 69 | <!DOCTYPE catalog PUBLIC |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 70 | "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" |
| 71 | "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> |
| 72 | <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> |
| 73 | <public publicId="-//OASIS//DTD DocBook XML V4.1.2//EN" |
| 74 | uri="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"/> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 75 | ...</pre><p>This is the beginning of a catalog for DocBook 4.1.2, XML Catalogs are |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 76 | written in XML, there is a specific namespace for catalog elements |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 77 | "urn:oasis:names:tc:entity:xmlns:xml:catalog". The first entry in this |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 78 | catalog is a <code>public</code> mapping it allows to associate a Public |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 79 | Identifier with an URI.</p><pre>... |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 80 | <rewriteSystem systemIdStartString="http://www.oasis-open.org/docbook/" |
| 81 | rewritePrefix="file:///usr/share/xml/docbook/"/> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 82 | ...</pre><p>A <code>rewriteSystem</code> is a very powerful instruction, it says that |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 83 | any URI starting with a given prefix should be looked at another URI |
| 84 | constructed by replacing the prefix with an new one. In effect this acts like |
| 85 | a cache system for a full area of the Web. In practice it is extremely useful |
| 86 | with a file prefix if you have installed a copy of those resources on your |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 87 | local system.</p><pre>... |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 88 | <delegatePublic publicIdStartString="-//OASIS//DTD XML Catalog //" |
| 89 | catalog="file:///usr/share/xml/docbook.xml"/> |
| 90 | <delegatePublic publicIdStartString="-//OASIS//ENTITIES DocBook XML" |
| 91 | catalog="file:///usr/share/xml/docbook.xml"/> |
| 92 | <delegatePublic publicIdStartString="-//OASIS//DTD DocBook XML" |
| 93 | catalog="file:///usr/share/xml/docbook.xml"/> |
| 94 | <delegateSystem systemIdStartString="http://www.oasis-open.org/docbook/" |
| 95 | catalog="file:///usr/share/xml/docbook.xml"/> |
| 96 | <delegateURI uriStartString="http://www.oasis-open.org/docbook/" |
| 97 | catalog="file:///usr/share/xml/docbook.xml"/> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 98 | ...</pre><p>Delegation is the core features which allows to build a tree of catalogs, |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 99 | easier to maintain than a single catalog, based on Public Identifier, System |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 100 | Identifier or URI prefixes it instructs the catalog software to look up |
| 101 | entries in another resource. This feature allow to build hierarchies of |
| 102 | catalogs, the set of entries presented should be sufficient to redirect the |
| 103 | resolution of all DocBook references to the specific catalog in |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 104 | <code>/usr/share/xml/docbook.xml</code> this one in turn could delegate all |
| 105 | references for DocBook 4.2.1 to a specific catalog installed at the same time |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 106 | as the DocBook resources on the local machine.</p><h3><a name="reference" id="reference">How to tune catalog usage:</a></h3><p>The user can change the default catalog behaviour by redirecting queries |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 107 | to its own set of catalogs, this can be done by setting the |
| 108 | <code>XML_CATALOG_FILES</code> environment variable to a list of catalogs, an |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 109 | empty one should deactivate loading the default <code>/etc/xml/catalog</code> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 110 | default catalog</p><h3><a name="validate" id="validate">How to debug catalog processing:</a></h3><p>Setting up the <code>XML_DEBUG_CATALOG</code> environment variable will |
Daniel Veillard | 8a46917 | 2003-06-12 16:05:07 +0000 | [diff] [blame] | 111 | make libxml2 output debugging informations for each catalog operations, for |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 112 | example:</p><pre>orchis:~/XML -> xmllint --memory --noout test/ent2 |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 113 | warning: failed to load external entity "title.xml" |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 114 | orchis:~/XML -> export XML_DEBUG_CATALOG= |
| 115 | orchis:~/XML -> xmllint --memory --noout test/ent2 |
| 116 | Failed to parse catalog /etc/xml/catalog |
| 117 | Failed to parse catalog /etc/xml/catalog |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 118 | warning: failed to load external entity "title.xml" |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 119 | Catalogs cleanup |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 120 | orchis:~/XML -> </pre><p>The test/ent2 references an entity, running the parser from memory makes |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 121 | the base URI unavailable and the the "title.xml" entity cannot be loaded. |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 122 | Setting up the debug environment variable allows to detect that an attempt is |
| 123 | made to load the <code>/etc/xml/catalog</code> but since it's not present the |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 124 | resolution fails.</p><p>But the most advanced way to debug XML catalog processing is to use the |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 125 | <strong>xmlcatalog</strong> command shipped with libxml2, it allows to load |
| 126 | catalogs and make resolution queries to see what is going on. This is also |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 127 | used for the regression tests:</p><pre>orchis:~/XML -> ./xmlcatalog test/catalogs/docbook.xml \ |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 128 | "-//OASIS//DTD DocBook XML V4.1.2//EN" |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 129 | http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 130 | orchis:~/XML -> </pre><p>For debugging what is going on, adding one -v flags increase the verbosity |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 131 | level to indicate the processing done (adding a second flag also indicate |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 132 | what elements are recognized at parsing):</p><pre>orchis:~/XML -> ./xmlcatalog -v test/catalogs/docbook.xml \ |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 133 | "-//OASIS//DTD DocBook XML V4.1.2//EN" |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 134 | Parsing catalog test/catalogs/docbook.xml's content |
| 135 | Found public match -//OASIS//DTD DocBook XML V4.1.2//EN |
| 136 | http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd |
| 137 | Catalogs cleanup |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 138 | orchis:~/XML -> </pre><p>A shell interface is also available to debug and process multiple queries |
| 139 | (and for regression tests):</p><pre>orchis:~/XML -> ./xmlcatalog -shell test/catalogs/docbook.xml \ |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 140 | "-//OASIS//DTD DocBook XML V4.1.2//EN" |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 141 | > help |
| 142 | Commands available: |
| 143 | public PublicID: make a PUBLIC identifier lookup |
| 144 | system SystemID: make a SYSTEM identifier lookup |
| 145 | resolve PublicID SystemID: do a full resolver lookup |
| 146 | add 'type' 'orig' 'replace' : add an entry |
| 147 | del 'values' : remove values |
| 148 | dump: print the current catalog state |
| 149 | debug: increase the verbosity level |
| 150 | quiet: decrease the verbosity level |
| 151 | exit: quit the shell |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 152 | > public "-//OASIS//DTD DocBook XML V4.1.2//EN" |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 153 | http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd |
| 154 | > quit |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 155 | orchis:~/XML -> </pre><p>This should be sufficient for most debugging purpose, this was actually |
| 156 | used heavily to debug the XML Catalog implementation itself.</p><h3><a name="Declaring" id="Declaring">How to create and maintain</a> catalogs:</h3><p>Basically XML Catalogs are XML files, you can either use XML tools to |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 157 | manage them or use <strong>xmlcatalog</strong> for this. The basic step is |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 158 | to create a catalog the -create option provide this facility:</p><pre>orchis:~/XML -> ./xmlcatalog --create tst.xml |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 159 | <?xml version="1.0"?> |
| 160 | <!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" |
| 161 | "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> |
| 162 | <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"/> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 163 | orchis:~/XML -> </pre><p>By default xmlcatalog does not overwrite the original catalog and save the |
MDT 2001 John Fleck | 0468500 | 2001-09-03 16:11:47 +0000 | [diff] [blame] | 164 | result on the standard output, this can be overridden using the -noout |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 165 | option. The <code>-add</code> command allows to add entries in the |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 166 | catalog:</p><pre>orchis:~/XML -> ./xmlcatalog --noout --create --add "public" \ |
| 167 | "-//OASIS//DTD DocBook XML V4.1.2//EN" \ |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 168 | http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd tst.xml |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 169 | orchis:~/XML -> cat tst.xml |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 170 | <?xml version="1.0"?> |
| 171 | <!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" \ |
| 172 | "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> |
| 173 | <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> |
| 174 | <public publicId="-//OASIS//DTD DocBook XML V4.1.2//EN" |
| 175 | uri="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"/> |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 176 | </catalog> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 177 | orchis:~/XML -> </pre><p>The <code>-add</code> option will always take 3 parameters even if some of |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 178 | the XML Catalog constructs (like nextCatalog) will have only a single |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 179 | argument, just pass a third empty string, it will be ignored.</p><p>Similarly the <code>-del</code> option remove matching entries from the |
| 180 | catalog:</p><pre>orchis:~/XML -> ./xmlcatalog --del \ |
Daniel Veillard | 024f199 | 2003-12-10 16:43:49 +0000 | [diff] [blame] | 181 | "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" tst.xml |
| 182 | <?xml version="1.0"?> |
| 183 | <!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" |
| 184 | "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> |
| 185 | <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"/> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 186 | orchis:~/XML -> </pre><p>The catalog is now empty. Note that the matching of <code>-del</code> is |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 187 | exact and would have worked in a similar fashion with the Public ID |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 188 | string.</p><p>This is rudimentary but should be sufficient to manage a not too complex |
| 189 | catalog tree of resources.</p><h3><a name="implemento" id="implemento">The implementor corner quick review of the |
| 190 | API:</a></h3><p>First, and like for every other module of libxml, there is an |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 191 | automatically generated <a href="html/libxml-catalog.html">API page for |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 192 | catalog support</a>.</p><p>The header for the catalog interfaces should be included as:</p><pre>#include <libxml/catalog.h></pre><p>The API is voluntarily kept very simple. First it is not obvious that |
Daniel Veillard | ffb120d | 2001-08-23 00:52:23 +0000 | [diff] [blame] | 193 | applications really need access to it since it is the default behaviour of |
Daniel Veillard | 95c09d9 | 2003-07-07 12:11:06 +0000 | [diff] [blame] | 194 | libxml2 (Note: it is possible to completely override libxml2 default catalog |
| 195 | by using <a href="html/libxml-parser.html">xmlSetExternalEntityLoader</a> to |
Daniel Veillard | 8a46917 | 2003-06-12 16:05:07 +0000 | [diff] [blame] | 196 | plug an application specific resolver).</p><p>Basically libxml2 support 2 catalog lists:</p><ul><li>the default one, global shared by all the application</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 197 | <li>a per-document catalog, this one is built if the document uses the |
Daniel Veillard | ffb120d | 2001-08-23 00:52:23 +0000 | [diff] [blame] | 198 | <code>oasis-xml-catalog</code> PIs to specify its own catalog list, it is |
| 199 | associated to the parser context and destroyed when the parsing context |
| 200 | is destroyed.</li> |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 201 | </ul><p>the document one will be used first if it exists.</p><h4>Initialization routines:</h4><p>xmlInitializeCatalog(), xmlLoadCatalog() and xmlLoadCatalogs() should be |
Daniel Veillard | ffb120d | 2001-08-23 00:52:23 +0000 | [diff] [blame] | 202 | used at startup to initialize the catalog, if the catalog should be |
| 203 | initialized with specific values xmlLoadCatalog() or xmlLoadCatalogs() |
| 204 | should be called before xmlInitializeCatalog() which would otherwise do a |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 205 | default initialization first.</p><p>The xmlCatalogAddLocal() call is used by the parser to grow the document |
| 206 | own catalog list if needed.</p><h4>Preferences setup:</h4><p>The XML Catalog spec requires the possibility to select default |
Daniel Veillard | ffb120d | 2001-08-23 00:52:23 +0000 | [diff] [blame] | 207 | preferences between public and system delegation, |
| 208 | xmlCatalogSetDefaultPrefer() allows this, xmlCatalogSetDefaults() and |
| 209 | xmlCatalogGetDefaults() allow to control if XML Catalogs resolution should |
| 210 | be forbidden, allowed for global catalog, for document catalog or both, the |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 211 | default is to allow both.</p><p>And of course xmlCatalogSetDebug() allows to generate debug messages |
| 212 | (through the xmlGenericError() mechanism).</p><h4>Querying routines:</h4><p>xmlCatalogResolve(), xmlCatalogResolveSystem(), xmlCatalogResolvePublic() |
Daniel Veillard | ffb120d | 2001-08-23 00:52:23 +0000 | [diff] [blame] | 213 | and xmlCatalogResolveURI() are relatively explicit if you read the XML |
| 214 | Catalog specification they correspond to section 7 algorithms, they should |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 215 | also work if you have loaded an SGML catalog with a simplified semantic.</p><p>xmlCatalogLocalResolve() and xmlCatalogLocalResolveURI() are the same but |
| 216 | operate on the document catalog list</p><h4>Cleanup and Miscellaneous:</h4><p>xmlCatalogCleanup() free-up the global catalog, xmlCatalogFreeLocal() is |
| 217 | the per-document equivalent.</p><p>xmlCatalogAdd() and xmlCatalogRemove() are used to dynamically modify the |
Daniel Veillard | ffb120d | 2001-08-23 00:52:23 +0000 | [diff] [blame] | 218 | first catalog in the global list, and xmlCatalogDump() allows to dump a |
| 219 | catalog state, those routines are primarily designed for xmlcatalog, I'm not |
| 220 | sure that exposing more complex interfaces (like navigation ones) would be |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 221 | really useful.</p><p>The xmlParseCatalogFile() is a function used to load XML Catalog files, |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 222 | it's similar as xmlParseFile() except it bypass all catalog lookups, it's |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 223 | provided because this functionality may be useful for client tools.</p><h4>threaded environments:</h4><p>Since the catalog tree is built progressively, some care has been taken to |
Daniel Veillard | b8cfbd1 | 2001-10-25 10:53:28 +0000 | [diff] [blame] | 224 | try to avoid troubles in multithreaded environments. The code is now thread |
Daniel Veillard | 8a46917 | 2003-06-12 16:05:07 +0000 | [diff] [blame] | 225 | safe assuming that the libxml2 library has been compiled with threads |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 226 | support.</p><p></p><h3><a name="Other" id="Other">Other resources</a></h3><p>The XML Catalog specification is relatively recent so there isn't much |
| 227 | literature to point at:</p><ul><li>You can find a good rant from Norm Walsh about <a href="http://www.arbortext.com/Think_Tank/XML_Resources/Issue_Three/issue_three.html">the |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 228 | need for catalogs</a>, it provides a lot of context informations even if |
Daniel Veillard | 93d3a47 | 2002-04-26 14:04:55 +0000 | [diff] [blame] | 229 | I don't agree with everything presented. Norm also wrote a more recent |
| 230 | article <a href="http://wwws.sun.com/software/xml/developers/resolver/article/">XML |
| 231 | entities and URI resolvers</a> describing them.</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 232 | <li>An <a href="http://home.ccil.org/~cowan/XML/XCatalog.html">old XML |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 233 | catalog proposal</a> from John Cowan</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 234 | <li>The <a href="http://www.rddl.org/">Resource Directory Description |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 235 | Language</a> (RDDL) another catalog system but more oriented toward |
| 236 | providing metadata for XML namespaces.</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 237 | <li>the page from the OASIS Technical <a href="http://www.oasis-open.org/committees/entity/">Committee on Entity |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 238 | Resolution</a> who maintains XML Catalog, you will find pointers to the |
| 239 | specification update, some background and pointers to others tools |
| 240 | providing XML Catalog support</li> |
Daniel Veillard | abfca61 | 2004-01-07 23:38:02 +0000 | [diff] [blame] | 241 | <li>There is a <a href="buildDocBookCatalog">shell script</a> to generate |
Daniel Veillard | 35e937a | 2002-01-19 22:21:54 +0000 | [diff] [blame] | 242 | XML Catalogs for DocBook 4.1.2 . If it can write to the /etc/xml/ |
| 243 | directory, it will set-up /etc/xml/catalog and /etc/xml/docbook based on |
| 244 | the resources found on the system. Otherwise it will just create |
| 245 | ~/xmlcatalog and ~/dbkxmlcatalog and doing: |
Daniel Veillard | 8594de9 | 2003-04-25 10:08:44 +0000 | [diff] [blame] | 246 | <p><code>export XML_CATALOG_FILES=$HOME/xmlcatalog</code></p> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 247 | <p>should allow to process DocBook documentations without requiring |
Daniel Veillard | 63d8314 | 2002-05-20 06:51:05 +0000 | [diff] [blame] | 248 | network accesses for the DTD or stylesheets</p> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 249 | </li> |
| 250 | <li>I have uploaded <a href="ftp://xmlsoft.org/test/dbk412catalog.tar.gz">a |
Daniel Veillard | 35e937a | 2002-01-19 22:21:54 +0000 | [diff] [blame] | 251 | small tarball</a> containing XML Catalogs for DocBook 4.1.2 which seems |
| 252 | to work fine for me too</li> |
Daniel Veillard | 0b28e88 | 2002-07-24 23:47:05 +0000 | [diff] [blame] | 253 | <li>The <a href="http://www.xmlsoft.org/xmlcatalog_man.html">xmlcatalog |
Daniel Veillard | 1177ca4 | 2003-04-26 22:29:54 +0000 | [diff] [blame] | 254 | manual page</a></li> |
| 255 | </ul><p>If you have suggestions for corrections or additions, simply contact |
| 256 | me:</p><p><a href="bugs.html">Daniel Veillard</a></p></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></body></html> |