blob: af7ea69b89e0f2b9220c29a34bde5f1db11c76f4 [file] [log] [blame]
Daniel Veillardb8cfbd12001-10-25 10:53:28 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/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">
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>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +000014</head>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000015<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 &amp; 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</ul></td></tr>
70</table>
71</td></tr></table></td>
72<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 +000073<p>Table of Content:</p>
74<ol>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000075<li><a href="General2">General overview</a></li>
76<li><a href="#definition">The definition</a></li>
77<li><a href="#Simple">Using catalogs</a></li>
78<li><a href="#Some">Some examples</a></li>
79<li><a href="#reference">How to tune catalog usage</a></li>
80<li><a href="#validate">How to debug catalog processing</a></li>
81<li><a href="#Declaring">How to create and maintain catalogs</a></li>
82<li><a href="#implemento">The implementor corner quick review of the
Daniel Veillarde7ead2d2001-08-22 23:44:09 +000083 API</a></li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000084<li><a href="#Other">Other resources</a></li>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +000085</ol>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000086<h3><a name="General2">General overview</a></h3>
87<p>What is a catalog? Basically it's a lookup mechanism used when an entity
88(a file or a remote resource) references another entity. The catalog lookup
89is inserted between the moment the reference is recognized by the software
90(XML parser, stylesheet processing, or even images referenced for inclusion
91in a rendering) and the time where loading that resource is actually
92started.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +000093<p>It is basically used for 3 things:</p>
94<ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000095<li>mapping from &quot;logical&quot; names, the public identifiers and a more
Daniel Veillarde7ead2d2001-08-22 23:44:09 +000096 concrete name usable for download (and URI). For example it can associate
Daniel Veillardffb120d2001-08-23 00:52:23 +000097 the logical name
Daniel Veillardb8cfbd12001-10-25 10:53:28 +000098 <p>&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;</p>
99<p>of the DocBook 4.1.2 XML DTD with the actual URL where it can be
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000100 downloaded</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000101<p>http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd</p>
102</li>
103<li>remapping from a given URL to another one, like an HTTP indirection
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000104 saying that
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000105 <p>&quot;http://www.oasis-open.org/committes/tr.xsl&quot;</p>
106<p>should really be looked at</p>
107<p>&quot;http://www.oasis-open.org/committes/entity/stylesheets/base/tr.xsl&quot;</p>
108</li>
109<li>providing a local cache mechanism allowing to load the entities
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000110 associated to public identifiers or remote resources, this is a really
111 important feature for any significant deployment of XML or SGML since it
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000112 allows to avoid the aleas and delays associated to fetching remote
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000113 resources.</li>
114</ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000115<h3><a name="definition">The definitions</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000116<p>Libxml, as of 2.4.3 implements 2 kind of catalogs:</p>
117<ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000118<li>the older SGML catalogs, the official spec is SGML Open Technical
119 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 +0000120 James Clark. This is relatively old and not the preferred mode of
121 operation of libxml.</li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000122<li>
123<a href="http://www.oasis-open.org/committees/entity/spec.html">XML
Daniel Veillardffb120d2001-08-23 00:52:23 +0000124 Catalogs</a>
125 is far more flexible, more recent, uses an XML syntax and should scale
126 quite better. This is the default option of libxml.</li>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000127</ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000128<p>
129<h3><a name="Simple">Using catalog</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000130<p>In a normal environment libxml will by default check the presence of a
131catalog in /etc/xml/catalog, and assuming it has been correctly populated,
132the processing is completely transparent to the document user. To take a
133concrete example, suppose you are authoring a DocBook document, this one
134starts with the following DOCTYPE definition:</p>
135<pre>&lt;?xml version='1.0'?&gt;
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000136&lt;!DOCTYPE book PUBLIC &quot;-//Norman Walsh//DTD DocBk XML V3.1.4//EN&quot;
137 &quot;http://nwalsh.com/docbook/xml/3.1.4/db3xml.dtd&quot;&gt;</pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000138<p>When validating the document with libxml, the catalog will be
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000139automatically consulted to lookup the public identifier &quot;-//Norman Walsh//DTD
140DocBk XML V3.1.4//EN&quot; and the system identifier
141&quot;http://nwalsh.com/docbook/xml/3.1.4/db3xml.dtd&quot;, and if these entities have
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000142been installed on your system and the catalogs actually point to them, libxml
143will fetch them from the local disk.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000144<p style="font-size: 10pt">
145<strong>Note</strong>: Really don't use this
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000146DOCTYPE example it's a really old version, but is fine as an example.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000147<p>Libxml will check the catalog each time that it is requested to load an
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000148entity, this includes DTD, external parsed entities, stylesheets, etc ... If
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000149your system is correctly configured all the authoring phase and processing
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000150should use only local files, even if your document stays portable because it
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000151uses the canonical public and system ID, referencing the remote document.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000152<h3><a name="Some">Some examples:</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000153<p>Here is a couple of fragments from XML Catalogs used in libxml early
154regression tests in <code>test/catalogs</code> :</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000155<pre>&lt;?xml version=&quot;1.0&quot;?&gt;
156&lt;!DOCTYPE catalog PUBLIC
157 &quot;-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN&quot;
158 &quot;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd&quot;&gt;
159&lt;catalog xmlns=&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;&gt;
160 &lt;public publicId=&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
161 uri=&quot;http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000162...</pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000163<p>This is the beginning of a catalog for DocBook 4.1.2, XML Catalogs are
164written in XML, there is a specific namespace for catalog elements
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000165&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;. The first entry in this
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000166catalog is a <code>public</code> mapping it allows to associate a Public
Daniel Veillardffb120d2001-08-23 00:52:23 +0000167Identifier with an URI.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000168<pre>...
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000169 &lt;rewriteSystem systemIdStartString=&quot;http://www.oasis-open.org/docbook/&quot;
170 rewritePrefix=&quot;file:///usr/share/xml/docbook/&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000171...</pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000172<p>A <code>rewriteSystem</code> is a very powerful instruction, it says that
173any URI starting with a given prefix should be looked at another URI
174constructed by replacing the prefix with an new one. In effect this acts like
175a cache system for a full area of the Web. In practice it is extremely useful
176with a file prefix if you have installed a copy of those resources on your
Daniel Veillardffb120d2001-08-23 00:52:23 +0000177local system.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000178<pre>...
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000179&lt;delegatePublic publicIdStartString=&quot;-//OASIS//DTD XML Catalog //&quot;
180 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
181&lt;delegatePublic publicIdStartString=&quot;-//OASIS//ENTITIES DocBook XML&quot;
182 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
183&lt;delegatePublic publicIdStartString=&quot;-//OASIS//DTD DocBook XML&quot;
184 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
185&lt;delegateSystem systemIdStartString=&quot;http://www.oasis-open.org/docbook/&quot;
186 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
187&lt;delegateURI uriStartString=&quot;http://www.oasis-open.org/docbook/&quot;
188 catalog=&quot;file:///usr/share/xml/docbook.xml&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000189...</pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000190<p>Delegation is the core features which allows to build a tree of catalogs,
191easier to maintain than a single catalog, based on Public Identifier, System
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000192Identifier or URI prefixes it instructs the catalog software to look up
193entries in another resource. This feature allow to build hierarchies of
194catalogs, the set of entries presented should be sufficient to redirect the
195resolution of all DocBook references to the specific catalog in
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000196<code>/usr/share/xml/docbook.xml</code> this one in turn could delegate all
197references for DocBook 4.2.1 to a specific catalog installed at the same time
198as the DocBook resources on the local machine.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000199<h3><a name="reference">How to tune catalog usage:</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000200<p>The user can change the default catalog behaviour by redirecting queries
201to its own set of catalogs, this can be done by setting the
202<code>XML_CATALOG_FILES</code> environment variable to a list of catalogs, an
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000203empty one should deactivate loading the default <code>/etc/xml/catalog</code>
204default catalog</p>
205<h3><a name="validate">How to debug catalog processing:</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000206<p>Setting up the <code>XML_DEBUG_CATALOG</code> environment variable will
207make libxml output debugging informations for each catalog operations, for
208example:</p>
209<pre>orchis:~/XML -&gt; xmllint --memory --noout test/ent2
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000210warning: failed to load external entity &quot;title.xml&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000211orchis:~/XML -&gt; export XML_DEBUG_CATALOG=
212orchis:~/XML -&gt; xmllint --memory --noout test/ent2
213Failed to parse catalog /etc/xml/catalog
214Failed to parse catalog /etc/xml/catalog
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000215warning: failed to load external entity &quot;title.xml&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000216Catalogs cleanup
217orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000218<p>The test/ent2 references an entity, running the parser from memory makes
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000219the base URI unavailable and the the &quot;title.xml&quot; entity cannot be loaded.
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000220Setting up the debug environment variable allows to detect that an attempt is
221made to load the <code>/etc/xml/catalog</code> but since it's not present the
Daniel Veillardffb120d2001-08-23 00:52:23 +0000222resolution fails.</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000223<p>But the most advanced way to debug XML catalog processing is to use the
224<strong>xmlcatalog</strong> command shipped with libxml2, it allows to load
225catalogs and make resolution queries to see what is going on. This is also
226used for the regression tests:</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000227<pre>orchis:~/XML -&gt; ./xmlcatalog test/catalogs/docbook.xml \
228 &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000229http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
230orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000231<p>For debugging what is going on, adding one -v flags increase the verbosity
232level to indicate the processing done (adding a second flag also indicate
233what elements are recognized at parsing):</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000234<pre>orchis:~/XML -&gt; ./xmlcatalog -v test/catalogs/docbook.xml \
235 &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000236Parsing catalog test/catalogs/docbook.xml's content
237Found public match -//OASIS//DTD DocBook XML V4.1.2//EN
238http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
239Catalogs cleanup
240orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000241<p>A shell interface is also available to debug and process multiple queries
242(and for regression tests):</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000243<pre>orchis:~/XML -&gt; ./xmlcatalog -shell test/catalogs/docbook.xml \
244 &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000245&gt; help
246Commands available:
247public PublicID: make a PUBLIC identifier lookup
248system SystemID: make a SYSTEM identifier lookup
249resolve PublicID SystemID: do a full resolver lookup
250add 'type' 'orig' 'replace' : add an entry
251del 'values' : remove values
252dump: print the current catalog state
253debug: increase the verbosity level
254quiet: decrease the verbosity level
255exit: quit the shell
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000256&gt; public &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000257http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
258&gt; quit
259orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000260<p>This should be sufficient for most debugging purpose, this was actually
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000261used heavily to debug the XML Catalog implementation itself.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000262<h3>
263<a name="Declaring">How to create and maintain</a> catalogs:</h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000264<p>Basically XML Catalogs are XML files, you can either use XML tools to
265manage them or use <strong>xmlcatalog</strong> for this. The basic step is
266to create a catalog the -create option provide this facility:</p>
267<pre>orchis:~/XML -&gt; ./xmlcatalog --create tst.xml
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000268&lt;?xml version=&quot;1.0&quot;?&gt;
269&lt;!DOCTYPE catalog PUBLIC &quot;-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN&quot;
270 &quot;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd&quot;&gt;
271&lt;catalog xmlns=&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000272orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000273<p>By default xmlcatalog does not overwrite the original catalog and save the
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000274result on the standard output, this can be overridden using the -noout
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000275option. The <code>-add</code> command allows to add entries in the
276catalog:</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000277<pre>orchis:~/XML -&gt; ./xmlcatalog --noout --create --add &quot;public&quot; \
278 &quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot; \
279 http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd tst.xml
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000280orchis:~/XML -&gt; cat tst.xml
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000281&lt;?xml version=&quot;1.0&quot;?&gt;
282&lt;!DOCTYPE catalog PUBLIC &quot;-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN&quot; \
283 &quot;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd&quot;&gt;
284&lt;catalog xmlns=&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;&gt;
285&lt;public publicId=&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
286 uri=&quot;http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000287&lt;/catalog&gt;
288orchis:~/XML -&gt; </pre>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000289<p>The <code>-add</code> option will always take 3 parameters even if some of
290the XML Catalog constructs (like nextCatalog) will have only a single
291argument, just pass a third empty string, it will be ignored.</p>
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000292<p>Similarly the <code>-del</code> option remove matching entries from the
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000293catalog:</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000294<pre>orchis:~/XML -&gt; ./xmlcatalog --del \
295 &quot;http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd&quot; tst.xml
296&lt;?xml version=&quot;1.0&quot;?&gt;
297&lt;!DOCTYPE catalog PUBLIC &quot;-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN&quot;
298 &quot;http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd&quot;&gt;
299&lt;catalog xmlns=&quot;urn:oasis:names:tc:entity:xmlns:xml:catalog&quot;/&gt;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000300orchis:~/XML -&gt; </pre>
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000301<p>The catalog is now empty. Note that the matching of <code>-del</code> is
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000302exact and would have worked in a similar fashion with the Public ID
303string.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000304<p>This is rudimentary but should be sufficient to manage a not too complex
305catalog tree of resources.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000306<h3><a name="implemento">The implementor corner quick review of the
307API:</a></h3>
308<p>First, and like for every other module of libxml, there is an
309automatically generated <a href="html/libxml-catalog.html">API page for
310catalog support</a>.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000311<p>The header for the catalog interfaces should be included as:</p>
312<pre>#include &lt;libxml/catalog.h&gt;</pre>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000313<p>The API is voluntarily kept very simple. First it is not obvious that
314applications really need access to it since it is the default behaviour of
315libxml (Note: it is possible to completely override libxml default catalog by
316using <a href="html/libxml-parser.html">xmlSetExternalEntityLoader</a> to
317plug an application specific resolver).</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000318<p>Basically libxml support 2 catalog lists:</p>
319<ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000320<li>the default one, global shared by all the application</li>
321<li>a per-document catalog, this one is built if the document uses the
Daniel Veillardffb120d2001-08-23 00:52:23 +0000322 <code>oasis-xml-catalog</code> PIs to specify its own catalog list, it is
323 associated to the parser context and destroyed when the parsing context
324 is destroyed.</li>
325</ul>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000326<p>the document one will be used first if it exists.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000327<h4>Initialization routines:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000328<p>xmlInitializeCatalog(), xmlLoadCatalog() and xmlLoadCatalogs() should be
329used at startup to initialize the catalog, if the catalog should be
330initialized with specific values xmlLoadCatalog() or xmlLoadCatalogs()
331should be called before xmlInitializeCatalog() which would otherwise do a
332default initialization first.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000333<p>The xmlCatalogAddLocal() call is used by the parser to grow the document
334own catalog list if needed.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000335<h4>Preferences setup:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000336<p>The XML Catalog spec requires the possibility to select default
337preferences between public and system delegation,
338xmlCatalogSetDefaultPrefer() allows this, xmlCatalogSetDefaults() and
339xmlCatalogGetDefaults() allow to control if XML Catalogs resolution should
340be forbidden, allowed for global catalog, for document catalog or both, the
341default is to allow both.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000342<p>And of course xmlCatalogSetDebug() allows to generate debug messages
343(through the xmlGenericError() mechanism).</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000344<h4>Querying routines:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000345<p>xmlCatalogResolve(), xmlCatalogResolveSystem(), xmlCatalogResolvePublic()
346and xmlCatalogResolveURI() are relatively explicit if you read the XML
347Catalog specification they correspond to section 7 algorithms, they should
348also work if you have loaded an SGML catalog with a simplified semantic.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000349<p>xmlCatalogLocalResolve() and xmlCatalogLocalResolveURI() are the same but
350operate on the document catalog list</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000351<h4>Cleanup and Miscellaneous:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000352<p>xmlCatalogCleanup() free-up the global catalog, xmlCatalogFreeLocal() is
353the per-document equivalent.</p>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000354<p>xmlCatalogAdd() and xmlCatalogRemove() are used to dynamically modify the
355first catalog in the global list, and xmlCatalogDump() allows to dump a
356catalog state, those routines are primarily designed for xmlcatalog, I'm not
357sure that exposing more complex interfaces (like navigation ones) would be
358really useful.</p>
Daniel Veillard9f7b84b2001-08-23 15:31:19 +0000359<p>The xmlParseCatalogFile() is a function used to load XML Catalog files,
360it's similar as xmlParseFile() except it bypass all catalog lookups, it's
361provided because this functionality may be useful for client tools.</p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000362<h4>threaded environments:</h4>
Daniel Veillardffb120d2001-08-23 00:52:23 +0000363<p>Since the catalog tree is built progressively, some care has been taken to
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000364try to avoid troubles in multithreaded environments. The code is now thread
365safe assuming that the libxml library has been compiled with threads
366support.</p>
367<p>
368<h3><a name="Other">Other resources</a></h3>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000369<p>The XML Catalog specification is relatively recent so there isn't much
MDT 2001 John Fleck04685002001-09-03 16:11:47 +0000370literature to point at:</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000371<ul>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000372<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
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000373 need for catalogs</a>, it provides a lot of context informations even if
374 I don't agree with everything presented.</li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000375<li>An <a href="http://home.ccil.org/~cowan/XML/XCatalog.html">old XML
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000376 catalog proposal</a> from John Cowan</li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000377<li>The <a href="http://www.rddl.org/">Resource Directory Description
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000378 Language</a> (RDDL) another catalog system but more oriented toward
379 providing metadata for XML namespaces.</li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000380<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 +0000381 Resolution</a> who maintains XML Catalog, you will find pointers to the
382 specification update, some background and pointers to others tools
383 providing XML Catalog support</li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000384<li>I have uploaded <a href="ftp://xmlsoft.org/test/dbk412catalog.tar.gz">a
Daniel Veillard7e8a4f72001-08-24 12:14:55 +0000385 mall tarball</a> containing XML Catalogs for DocBook 4.1.2 which seems to
386 work fine for me</li>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000387<li>The <a href="http://www.xmlsoft.org/xmlcatalog_man.html">xmlcatalog
388 manual page</a>
389</li>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000390</ul>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000391<p>If you have suggestions for corrections or additions, simply contact
392me:</p>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000393<p><a href="mailto:daniel@veillard.com">Daniel Veillard</a></p>
Daniel Veillardb8cfbd12001-10-25 10:53:28 +0000394</td></tr></table></td></tr></table></td></tr></table></td>
395</tr></table></td></tr></table>
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000396</body>
397</html>