blob: 74a103ee20008329ac52d0dc3261a3ccbc398b6e [file] [log] [blame]
Daniel Veillard43d3f612001-11-10 11:57:23 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
Daniel Veillarde7ead2d2001-08-22 23:44:09 +00002<html>
3<head>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +00004<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
Daniel Veillardc332dab2002-03-29 14:08:27 +00005<link rel="SHORTCUT ICON" href="/favicon.ico">
Daniel Veillardb8cfbd12001-10-25 10:53:28 +00006<style type="text/css"><!--
Daniel Veillard373a4752002-02-21 14:46:29 +00007TD {font-family: Verdana,Arial,Helvetica}
8BODY {font-family: Verdana,Arial,Helvetica; margin-top: 2em; margin-left: 0em; margin-right: 0em}
9H1 {font-family: Verdana,Arial,Helvetica}
10H2 {font-family: Verdana,Arial,Helvetica}
11H3 {font-family: Verdana,Arial,Helvetica}
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000012A:link, A:visited, A:active { text-decoration: underline }
13--></style>
14<title>Catalog support</title>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +000015</head>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000016<body bgcolor="#8b7765" text="#000000" link="#000000" vlink="#000000">
17<table border="0" width="100%" cellpadding="5" cellspacing="0" align="center"><tr>
18<td width="180">
19<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>
20</td>
21<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">
22<h1>The XML C library for Gnome</h1>
23<h2>Catalog support</h2>
24</td></tr></table></td></tr></table></td>
25</tr></table>
26<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>
27<td valign="top" width="200" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td>
28<table width="100%" border="0" cellspacing="1" cellpadding="3">
29<tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Main Menu</b></center></td></tr>
Daniel Veillard8acca112002-01-21 09:52:27 +000030<tr><td bgcolor="#fffacd"><ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000031<li><a href="index.html">Home</a></li>
32<li><a href="intro.html">Introduction</a></li>
33<li><a href="FAQ.html">FAQ</a></li>
34<li><a href="docs.html">Documentation</a></li>
35<li><a href="bugs.html">Reporting bugs and getting help</a></li>
36<li><a href="help.html">How to help</a></li>
37<li><a href="downloads.html">Downloads</a></li>
38<li><a href="news.html">News</a></li>
Daniel Veillard7b602b42002-01-08 13:26:00 +000039<li><a href="XMLinfo.html">XML</a></li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000040<li><a href="XSLT.html">XSLT</a></li>
Daniel Veillard6dbcaf82002-02-20 14:37:47 +000041<li><a href="python.html">Python and bindings</a></li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000042<li><a href="architecture.html">libxml architecture</a></li>
43<li><a href="tree.html">The tree output</a></li>
44<li><a href="interface.html">The SAX interface</a></li>
45<li><a href="xmldtd.html">Validation &amp; DTDs</a></li>
46<li><a href="xmlmem.html">Memory Management</a></li>
47<li><a href="encoding.html">Encodings support</a></li>
48<li><a href="xmlio.html">I/O Interfaces</a></li>
49<li><a href="catalog.html">Catalog support</a></li>
50<li><a href="library.html">The parser interfaces</a></li>
51<li><a href="entities.html">Entities or no entities</a></li>
52<li><a href="namespaces.html">Namespaces</a></li>
53<li><a href="upgrade.html">Upgrading 1.x code</a></li>
Daniel Veillard52dcab32001-10-30 12:51:17 +000054<li><a href="threads.html">Thread safety</a></li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000055<li><a href="DOM.html">DOM Principles</a></li>
56<li><a href="example.html">A real example</a></li>
57<li><a href="contribs.html">Contributions</a></li>
Daniel Veillardfc59c092002-06-05 14:48:26 +000058<li><a href="tutorial/index.html">Tutorial</a></li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000059<li>
60<a href="xml.html">flat page</a>, <a href="site.xsl">stylesheet</a>
61</li>
62</ul></td></tr>
63</table>
64<table width="100%" border="0" cellspacing="1" cellpadding="3">
Daniel Veillard3bf65be2002-01-23 12:36:34 +000065<tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>API Indexes</b></center></td></tr>
66<tr><td bgcolor="#fffacd"><ul>
Daniel Veillardf8592562002-01-23 17:58:17 +000067<li><a href="APIchunk0.html">Alphabetic</a></li>
Daniel Veillard3bf65be2002-01-23 12:36:34 +000068<li><a href="APIconstructors.html">Constructors</a></li>
69<li><a href="APIfunctions.html">Functions/Types</a></li>
70<li><a href="APIfiles.html">Modules</a></li>
71<li><a href="APIsymbols.html">Symbols</a></li>
72</ul></td></tr>
73</table>
74<table width="100%" border="0" cellspacing="1" cellpadding="3">
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000075<tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Related links</b></center></td></tr>
Daniel Veillard8acca112002-01-21 09:52:27 +000076<tr><td bgcolor="#fffacd"><ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000077<li><a href="http://mail.gnome.org/archives/xml/">Mail archive</a></li>
78<li><a href="http://xmlsoft.org/XSLT/">XSLT libxslt</a></li>
Daniel Veillard4a859202002-01-08 11:49:22 +000079<li><a href="http://phd.cs.unibo.it/gdome2/">DOM gdome2</a></li>
Daniel Veillard2d347fa2002-03-17 10:34:11 +000080<li><a href="http://www.aleksey.com/xmlsec/">XML-DSig xmlsec</a></li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000081<li><a href="ftp://xmlsoft.org/">FTP</a></li>
82<li><a href="http://www.fh-frankfurt.de/~igor/projects/libxml/">Windows binaries</a></li>
Daniel Veillarddb9dfd92001-11-26 17:25:02 +000083<li><a href="http://garypennington.net/libxml2/">Solaris binaries</a></li>
Daniel Veillarde6d8e202002-05-02 06:11:10 +000084<li><a href="http://sourceforge.net/projects/libxml2-pas/">Pascal bindings</a></li>
Daniel Veillard2d347fa2002-03-17 10:34:11 +000085<li><a href="http://bugzilla.gnome.org/buglist.cgi?product=libxml&amp;product=libxml2">Bug Tracker</a></li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000086</ul></td></tr>
87</table>
88</td></tr></table></td>
89<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">
Daniel Veillarde7ead2d2001-08-22 23:44:09 +000090<p>Table of Content:</p>
91<ol>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000092<li><a href="General2">General overview</a></li>
Daniel Veillard0b28e882002-07-24 23:47:05 +000093 <li><a href="#definition">The definition</a></li>
94 <li><a href="#Simple">Using catalogs</a></li>
95 <li><a href="#Some">Some examples</a></li>
96 <li><a href="#reference">How to tune catalog usage</a></li>
97 <li><a href="#validate">How to debug catalog processing</a></li>
98 <li><a href="#Declaring">How to create and maintain catalogs</a></li>
99 <li><a href="#implemento">The implementor corner quick review of the
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000100 API</a></li>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000101 <li><a href="#Other">Other resources</a></li>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000102</ol>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000103<h3><a name="General2">General overview</a></h3>
104<p>What is a catalog? Basically it's a lookup mechanism used when an entity
105(a file or a remote resource) references another entity. The catalog lookup
106is inserted between the moment the reference is recognized by the software
107(XML parser, stylesheet processing, or even images referenced for inclusion
108in a rendering) and the time where loading that resource is actually
109started.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000110<p>It is basically used for 3 things:</p>
111<ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000112<li>mapping from &quot;logical&quot; names, the public identifiers and a more
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000113 concrete name usable for download (and URI). For example it can associate
Daniel Veillardffb120d2001-08-23 00:52:23 +0000114 the logical name
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000115 <p>&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;</p>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000116 <p>of the DocBook 4.1.2 XML DTD with the actual URL where it can be
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000117 downloaded</p>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000118 <p>http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd</p>
119 </li>
120 <li>remapping from a given URL to another one, like an HTTP indirection
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000121 saying that
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000122 <p>&quot;http://www.oasis-open.org/committes/tr.xsl&quot;</p>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000123 <p>should really be looked at</p>
124 <p>&quot;http://www.oasis-open.org/committes/entity/stylesheets/base/tr.xsl&quot;</p>
125 </li>
126 <li>providing a local cache mechanism allowing to load the entities
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000127 associated to public identifiers or remote resources, this is a really
128 important feature for any significant deployment of XML or SGML since it
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000129 allows to avoid the aleas and delays associated to fetching remote
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000130 resources.</li>
131</ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000132<h3><a name="definition">The definitions</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000133<p>Libxml, as of 2.4.3 implements 2 kind of catalogs:</p>
134<ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000135<li>the older SGML catalogs, the official spec is SGML Open Technical
136 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 Veillarde7ead2d2001-08-22 23:44:09 +0000137 James Clark. This is relatively old and not the preferred mode of
138 operation of libxml.</li>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000139 <li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000140<a href="http://www.oasis-open.org/committees/entity/spec.html">XML
Daniel Veillardaf43f632002-03-08 15:05:20 +0000141 Catalogs</a> is far more flexible, more recent, uses an XML syntax and
142 should scale quite better. This is the default option of libxml.</li>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000143</ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000144<p>
145<h3><a name="Simple">Using catalog</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000146<p>In a normal environment libxml will by default check the presence of a
147catalog in /etc/xml/catalog, and assuming it has been correctly populated,
148the processing is completely transparent to the document user. To take a
149concrete example, suppose you are authoring a DocBook document, this one
150starts with the following DOCTYPE definition:</p>
151<pre>&lt;?xml version='1.0'?&gt;
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000152&lt;!DOCTYPE book PUBLIC &quot;-//Norman Walsh//DTD DocBk XML V3.1.4//EN&quot;
153 &quot;http://nwalsh.com/docbook/xml/3.1.4/db3xml.dtd&quot;&gt;</pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000154<p>When validating the document with libxml, the catalog will be
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000155automatically consulted to lookup the public identifier &quot;-//Norman Walsh//DTD
156DocBk XML V3.1.4//EN&quot; and the system identifier
157&quot;http://nwalsh.com/docbook/xml/3.1.4/db3xml.dtd&quot;, and if these entities have
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000158been installed on your system and the catalogs actually point to them, libxml
159will fetch them from the local disk.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000160<p style="font-size: 10pt">
161<strong>Note</strong>: Really don't use this
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000162DOCTYPE example it's a really old version, but is fine as an example.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000163<p>Libxml will check the catalog each time that it is requested to load an
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000164entity, this includes DTD, external parsed entities, stylesheets, etc ... If
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000165your system is correctly configured all the authoring phase and processing
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000166should use only local files, even if your document stays portable because it
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000167uses the canonical public and system ID, referencing the remote document.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000168<h3><a name="Some">Some examples:</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000169<p>Here is a couple of fragments from XML Catalogs used in libxml early
170regression tests in <code>test/catalogs</code> :</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000171<pre>&lt;?xml version=&quot;1.0&quot;?&gt;
172&lt;!DOCTYPE catalog PUBLIC
173 &quot;-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN&quot;
174 &quot;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd&quot;&gt;
175&lt;catalog xmlns=&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;&gt;
176 &lt;public publicId=&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
177 uri=&quot;http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000178...</pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000179<p>This is the beginning of a catalog for DocBook 4.1.2, XML Catalogs are
180written in XML, there is a specific namespace for catalog elements
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000181&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;. The first entry in this
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000182catalog is a <code>public</code> mapping it allows to associate a Public
Daniel Veillardffb120d2001-08-23 00:52:23 +0000183Identifier with an URI.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000184<pre>...
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000185 &lt;rewriteSystem systemIdStartString=&quot;http://www.oasis-open.org/docbook/&quot;
186 rewritePrefix=&quot;file:///usr/share/xml/docbook/&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000187...</pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000188<p>A <code>rewriteSystem</code> is a very powerful instruction, it says that
189any URI starting with a given prefix should be looked at another URI
190constructed by replacing the prefix with an new one. In effect this acts like
191a cache system for a full area of the Web. In practice it is extremely useful
192with a file prefix if you have installed a copy of those resources on your
Daniel Veillardffb120d2001-08-23 00:52:23 +0000193local system.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000194<pre>...
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000195&lt;delegatePublic publicIdStartString=&quot;-//OASIS//DTD XML Catalog //&quot;
196 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
197&lt;delegatePublic publicIdStartString=&quot;-//OASIS//ENTITIES DocBook XML&quot;
198 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
199&lt;delegatePublic publicIdStartString=&quot;-//OASIS//DTD DocBook XML&quot;
200 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
201&lt;delegateSystem systemIdStartString=&quot;http://www.oasis-open.org/docbook/&quot;
202 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
203&lt;delegateURI uriStartString=&quot;http://www.oasis-open.org/docbook/&quot;
204 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000205...</pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000206<p>Delegation is the core features which allows to build a tree of catalogs,
207easier to maintain than a single catalog, based on Public Identifier, System
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000208Identifier or URI prefixes it instructs the catalog software to look up
209entries in another resource. This feature allow to build hierarchies of
210catalogs, the set of entries presented should be sufficient to redirect the
211resolution of all DocBook references to the specific catalog in
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000212<code>/usr/share/xml/docbook.xml</code> this one in turn could delegate all
213references for DocBook 4.2.1 to a specific catalog installed at the same time
214as the DocBook resources on the local machine.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000215<h3><a name="reference">How to tune catalog usage:</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000216<p>The user can change the default catalog behaviour by redirecting queries
217to its own set of catalogs, this can be done by setting the
218<code>XML_CATALOG_FILES</code> environment variable to a list of catalogs, an
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000219empty one should deactivate loading the default <code>/etc/xml/catalog</code>
220default catalog</p>
221<h3><a name="validate">How to debug catalog processing:</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000222<p>Setting up the <code>XML_DEBUG_CATALOG</code> environment variable will
223make libxml output debugging informations for each catalog operations, for
224example:</p>
225<pre>orchis:~/XML -&gt; xmllint --memory --noout test/ent2
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000226warning: failed to load external entity &quot;title.xml&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000227orchis:~/XML -&gt; export XML_DEBUG_CATALOG=
228orchis:~/XML -&gt; xmllint --memory --noout test/ent2
229Failed to parse catalog /etc/xml/catalog
230Failed to parse catalog /etc/xml/catalog
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000231warning: failed to load external entity &quot;title.xml&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000232Catalogs cleanup
233orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000234<p>The test/ent2 references an entity, running the parser from memory makes
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000235the base URI unavailable and the the &quot;title.xml&quot; entity cannot be loaded.
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000236Setting up the debug environment variable allows to detect that an attempt is
237made to load the <code>/etc/xml/catalog</code> but since it's not present the
Daniel Veillardffb120d2001-08-23 00:52:23 +0000238resolution fails.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000239<p>But the most advanced way to debug XML catalog processing is to use the
240<strong>xmlcatalog</strong> command shipped with libxml2, it allows to load
241catalogs and make resolution queries to see what is going on. This is also
242used for the regression tests:</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000243<pre>orchis:~/XML -&gt; ./xmlcatalog test/catalogs/docbook.xml \
244 &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000245http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
246orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000247<p>For debugging what is going on, adding one -v flags increase the verbosity
248level to indicate the processing done (adding a second flag also indicate
249what elements are recognized at parsing):</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000250<pre>orchis:~/XML -&gt; ./xmlcatalog -v test/catalogs/docbook.xml \
251 &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000252Parsing catalog test/catalogs/docbook.xml's content
253Found public match -//OASIS//DTD DocBook XML V4.1.2//EN
254http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
255Catalogs cleanup
256orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000257<p>A shell interface is also available to debug and process multiple queries
258(and for regression tests):</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000259<pre>orchis:~/XML -&gt; ./xmlcatalog -shell test/catalogs/docbook.xml \
260 &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000261&gt; help
262Commands available:
263public PublicID: make a PUBLIC identifier lookup
264system SystemID: make a SYSTEM identifier lookup
265resolve PublicID SystemID: do a full resolver lookup
266add 'type' 'orig' 'replace' : add an entry
267del 'values' : remove values
268dump: print the current catalog state
269debug: increase the verbosity level
270quiet: decrease the verbosity level
271exit: quit the shell
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000272&gt; public &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000273http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
274&gt; quit
275orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000276<p>This should be sufficient for most debugging purpose, this was actually
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000277used heavily to debug the XML Catalog implementation itself.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000278<h3>
279<a name="Declaring">How to create and maintain</a> catalogs:</h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000280<p>Basically XML Catalogs are XML files, you can either use XML tools to
281manage them or use <strong>xmlcatalog</strong> for this. The basic step is
282to create a catalog the -create option provide this facility:</p>
283<pre>orchis:~/XML -&gt; ./xmlcatalog --create tst.xml
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000284&lt;?xml version=&quot;1.0&quot;?&gt;
285&lt;!DOCTYPE catalog PUBLIC &quot;-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN&quot;
286 &quot;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd&quot;&gt;
287&lt;catalog xmlns=&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000288orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000289<p>By default xmlcatalog does not overwrite the original catalog and save the
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000290result on the standard output, this can be overridden using the -noout
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000291option. The <code>-add</code> command allows to add entries in the
292catalog:</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000293<pre>orchis:~/XML -&gt; ./xmlcatalog --noout --create --add &quot;public&quot; \
294 &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot; \
295 http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd tst.xml
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000296orchis:~/XML -&gt; cat tst.xml
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000297&lt;?xml version=&quot;1.0&quot;?&gt;
298&lt;!DOCTYPE catalog PUBLIC &quot;-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN&quot; \
299 &quot;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd&quot;&gt;
300&lt;catalog xmlns=&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;&gt;
301&lt;public publicId=&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
302 uri=&quot;http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000303&lt;/catalog&gt;
304orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000305<p>The <code>-add</code> option will always take 3 parameters even if some of
306the XML Catalog constructs (like nextCatalog) will have only a single
307argument, just pass a third empty string, it will be ignored.</p>
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000308<p>Similarly the <code>-del</code> option remove matching entries from the
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000309catalog:</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000310<pre>orchis:~/XML -&gt; ./xmlcatalog --del \
311 &quot;http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd&quot; tst.xml
312&lt;?xml version=&quot;1.0&quot;?&gt;
313&lt;!DOCTYPE catalog PUBLIC &quot;-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN&quot;
314 &quot;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd&quot;&gt;
315&lt;catalog xmlns=&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000316orchis:~/XML -&gt; </pre>
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000317<p>The catalog is now empty. Note that the matching of <code>-del</code> is
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000318exact and would have worked in a similar fashion with the Public ID
319string.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000320<p>This is rudimentary but should be sufficient to manage a not too complex
321catalog tree of resources.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000322<h3><a name="implemento">The implementor corner quick review of the
323API:</a></h3>
324<p>First, and like for every other module of libxml, there is an
325automatically generated <a href="html/libxml-catalog.html">API page for
326catalog support</a>.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000327<p>The header for the catalog interfaces should be included as:</p>
328<pre>#include &lt;libxml/catalog.h&gt;</pre>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000329<p>The API is voluntarily kept very simple. First it is not obvious that
330applications really need access to it since it is the default behaviour of
331libxml (Note: it is possible to completely override libxml default catalog by
332using <a href="html/libxml-parser.html">xmlSetExternalEntityLoader</a> to
333plug an application specific resolver).</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000334<p>Basically libxml support 2 catalog lists:</p>
335<ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000336<li>the default one, global shared by all the application</li>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000337 <li>a per-document catalog, this one is built if the document uses the
Daniel Veillardffb120d2001-08-23 00:52:23 +0000338 <code>oasis-xml-catalog</code> PIs to specify its own catalog list, it is
339 associated to the parser context and destroyed when the parsing context
340 is destroyed.</li>
341</ul>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000342<p>the document one will be used first if it exists.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000343<h4>Initialization routines:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000344<p>xmlInitializeCatalog(), xmlLoadCatalog() and xmlLoadCatalogs() should be
345used at startup to initialize the catalog, if the catalog should be
346initialized with specific values xmlLoadCatalog() or xmlLoadCatalogs()
347should be called before xmlInitializeCatalog() which would otherwise do a
348default initialization first.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000349<p>The xmlCatalogAddLocal() call is used by the parser to grow the document
350own catalog list if needed.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000351<h4>Preferences setup:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000352<p>The XML Catalog spec requires the possibility to select default
353preferences between public and system delegation,
354xmlCatalogSetDefaultPrefer() allows this, xmlCatalogSetDefaults() and
355xmlCatalogGetDefaults() allow to control if XML Catalogs resolution should
356be forbidden, allowed for global catalog, for document catalog or both, the
357default is to allow both.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000358<p>And of course xmlCatalogSetDebug() allows to generate debug messages
359(through the xmlGenericError() mechanism).</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000360<h4>Querying routines:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000361<p>xmlCatalogResolve(), xmlCatalogResolveSystem(), xmlCatalogResolvePublic()
362and xmlCatalogResolveURI() are relatively explicit if you read the XML
363Catalog specification they correspond to section 7 algorithms, they should
364also work if you have loaded an SGML catalog with a simplified semantic.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000365<p>xmlCatalogLocalResolve() and xmlCatalogLocalResolveURI() are the same but
366operate on the document catalog list</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000367<h4>Cleanup and Miscellaneous:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000368<p>xmlCatalogCleanup() free-up the global catalog, xmlCatalogFreeLocal() is
369the per-document equivalent.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000370<p>xmlCatalogAdd() and xmlCatalogRemove() are used to dynamically modify the
371first catalog in the global list, and xmlCatalogDump() allows to dump a
372catalog state, those routines are primarily designed for xmlcatalog, I'm not
373sure that exposing more complex interfaces (like navigation ones) would be
374really useful.</p>
Daniel Veillard9f7b84b2001-08-23 15:31:19 +0000375<p>The xmlParseCatalogFile() is a function used to load XML Catalog files,
376it's similar as xmlParseFile() except it bypass all catalog lookups, it's
377provided because this functionality may be useful for client tools.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000378<h4>threaded environments:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000379<p>Since the catalog tree is built progressively, some care has been taken to
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000380try to avoid troubles in multithreaded environments. The code is now thread
381safe assuming that the libxml library has been compiled with threads
382support.</p>
383<p>
384<h3><a name="Other">Other resources</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000385<p>The XML Catalog specification is relatively recent so there isn't much
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000386literature to point at:</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000387<ul>
Daniel Veillard63d83142002-05-20 06:51:05 +0000388<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 Veillarde7ead2d2001-08-22 23:44:09 +0000389 need for catalogs</a>, it provides a lot of context informations even if
Daniel Veillard93d3a472002-04-26 14:04:55 +0000390 I don't agree with everything presented. Norm also wrote a more recent
391 article <a href="http://wwws.sun.com/software/xml/developers/resolver/article/">XML
392 entities and URI resolvers</a> describing them.</li>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000393 <li>An <a href="http://home.ccil.org/~cowan/XML/XCatalog.html">old XML
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000394 catalog proposal</a> from John Cowan</li>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000395 <li>The <a href="http://www.rddl.org/">Resource Directory Description
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000396 Language</a> (RDDL) another catalog system but more oriented toward
397 providing metadata for XML namespaces.</li>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000398 <li>the page from the OASIS Technical <a href="http://www.oasis-open.org/committees/entity/">Committee on Entity
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000399 Resolution</a> who maintains XML Catalog, you will find pointers to the
400 specification update, some background and pointers to others tools
401 providing XML Catalog support</li>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000402 <li>Here is a <a href="buildDocBookCatalog">shell script</a> to generate
Daniel Veillard35e937a2002-01-19 22:21:54 +0000403 XML Catalogs for DocBook 4.1.2 . If it can write to the /etc/xml/
404 directory, it will set-up /etc/xml/catalog and /etc/xml/docbook based on
405 the resources found on the system. Otherwise it will just create
406 ~/xmlcatalog and ~/dbkxmlcatalog and doing:
Daniel Veillardc575b992002-02-08 13:28:40 +0000407 <p><code>export XMLCATALOG=$HOME/xmlcatalog</code></p>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000408 <p>should allow to process DocBook documentations without requiring
Daniel Veillard63d83142002-05-20 06:51:05 +0000409 network accesses for the DTD or stylesheets</p>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000410 </li>
411 <li>I have uploaded <a href="ftp://xmlsoft.org/test/dbk412catalog.tar.gz">a
Daniel Veillard35e937a2002-01-19 22:21:54 +0000412 small tarball</a> containing XML Catalogs for DocBook 4.1.2 which seems
413 to work fine for me too</li>
Daniel Veillard0b28e882002-07-24 23:47:05 +0000414 <li>The <a href="http://www.xmlsoft.org/xmlcatalog_man.html">xmlcatalog
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000415 manual page</a>
416</li>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000417</ul>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000418<p>If you have suggestions for corrections or additions, simply contact
419me:</p>
Daniel Veillard3f4c40f2002-02-13 09:19:28 +0000420<p><a href="bugs.html">Daniel Veillard</a></p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000421</td></tr></table></td></tr></table></td></tr></table></td>
422</tr></table></td></tr></table>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000423</body>
424</html>