source: release-kits/lirk3/resources/gs3-release-maker/ant/docs/manual/CoreTypes/xmlcatalog.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 12.4 KB
Line 
1<html>
2
3<head>
4<meta http-equiv="Content-Language" content="en-us">
5<title>XMLCatalog Type</title>
6<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
7</head>
8
9<body>
10
11<h2><a name="XMLCatalog">XMLCatalog</a></h2>
12
13<p>An XMLCatalog is a catalog of public resources such as DTDs or
14entities that are referenced in an XML document. Catalogs are
15typically used to make web references to resources point to a locally
16cached copy of the resource.</p>
17
18<p>This allows the XML Parser, XSLT Processor or other consumer of XML
19documents
20to efficiently allow a local substitution for a resource available on the
21web.
22</p>
23<p><b>Note:</b> This task <em>uses, but does not depend on</em> external
24libraries not included in the Ant distribution. See <a
25 href="../install.html#librarydependencies">Library Dependencies</a> for more
26information.</p>
27<p>This data type provides a catalog of resource locations based
28on the <a
29href="http://oasis-open.org/committees/entity/spec-2001-08-06.html">
30OASIS "Open Catalog" standard</a>. The catalog entries are used
31both for Entity resolution and URI resolution, in accordance with
32the <code>org.xml.sax.EntityResolver</code> and <code>
33javax.xml.transform.URIResolver</code> interfaces as defined
34in the <a href="http://java.sun.com/xml/jaxp">Java API for XML
35Processing (JAXP) Specification</a>.</p>
36<p>For example, in a <code>web.xml</code> file, the DTD is referenced as:
37<pre>
38&lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&quot;
39 &quot;http://java.sun.com/j2ee/dtds/web-app_2_2.dtd&quot;&gt;
40</pre>
41The XML processor, without XMLCatalog support, would need to retrieve the
42DTD from
43the URL specified whenever validation of the document was required.
44</p>
45<p>This can be very time consuming during the build process,
46especially where network throughput is limited. Alternatively, you
47can do the following:
48<ol>
49<li>Copy <code>web-app_2_2.dtd</code> onto your local disk somewhere (either in the
50filesystem or even embedded inside a jar or zip file on the classpath).</li>
51<li>Create an <code>&lt;xmlcatalog&gt;</code> with a <code>&lt;dtd&gt;</code>
52element whose <code>location</code> attribute points to the file.</li>
53<li>Success! The XML processor will now use the local copy instead of calling out
54to the internet.</li>
55</ol>
56</p>
57<p>XMLCatalogs can appear inside tasks
58that support this feature or at the same level as <code>target</code>
59- i.e., as children of <code>project</code> for reuse across different
60tasks,
61e.g. XML Validation and XSLT Transformation. The XML Validate task
62uses XMLCatalogs for entity resolution. The XSLT Transformation
63task uses XMLCatalogs for both entity and URI resolution.</p>
64<p>XMLCatalogs are specified as either a reference to another
65XMLCatalog, defined previously in a build file, or as a list of
66<code>dtd</code> or <code>entity</code> locations. In addition,
67external catalog files may be specified in a nested <code>catalogpath</code> ,
68but they will be ignored unless the resolver library from
69xml-commons is available in the system classpath. <b>Due to backwards
70incompatible changes in the resolver code after the release of
71resolver 1.0, Ant will not support resolver.jar in version 1.0 - we
72expect a resolver release 1.1 to happen before Ant 1.6 gets
73released.</b> A separate classpath for entity resolution may be
74specified inline via nested <code>classpath</code> elements; otherwise
75the system classpath is used for this as well.</p>
76<p>XMLCatalogs can also be nested inside other XMLCatalogs. For
77example, a "superset" XMLCatalog could be made by including several
78nested XMLCatalogs that referred to other, previously defined
79XMLCatalogs.</p>
80<p>Resource locations can be specified either in-line or in
81external catalog file(s), or both. In order to use an external
82catalog file, the xml-commons resolver library ("resolver.jar")
83must be in your path. External catalog files may be either <a
84href="http://oasis-open.org/committees/entity/background/9401.html">
85plain text format</a> or <a
86href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
87XML format</a>. If the xml-commons resolver library is not found in the
88classpath, external catalog files, specified in <code>catalogpath</code>,
89will be ignored and a warning
90will be logged. In this case, however, processing of inline entries will
91proceed normally.</p>
92<p>Currently, only <code>&lt;dtd&gt;</code> and
93<code>&lt;entity&gt;</code> elements may be specified inline; these
94roughly correspond to OASIS catalog entry types <code>PUBLIC</code> and
95<code>URI</code> respectively. By contrast, external catalog files
96may use any of the entry types defined in the
97<a href="http://oasis-open.org/committees/entity/spec-2001-08-06.html">
98+OASIS specification</a>.</p>
99<h3><a name="ResolverAlgorithm">Entity/DTD/URI Resolution Algorithm</a></h3>
100
101When an entity, DTD, or URI is looked up by the XML processor, the
102XMLCatalog searches its list of entries to see if any match. That is,
103it attempts to match the <code>publicId</code> attribute of each entry
104with the PublicID or URI of the entity to be resolved. Assuming a
105matching entry is found, XMLCatalog then executes the following steps:
106
107<h4>1. Filesystem lookup</h4>
108
109<p>The <code>location</code> is first looked up in the filesystem. If
110the <code>location</code> is a relative path, the ant project basedir
111attribute is used as the base directory. If the <code>location</code>
112specifies an absolute path, it is used as is. Once we have an
113absolute path in hand, we check to see if a valid and readable file
114exists at that path. If so, we are done. If not, we proceed to the
115next step.</p>
116
117<h4>2. Classpath lookup</h4>
118
119<p>The <code>location</code> is next looked up in the classpath.
120Recall that jar files are merely fancy zip files. For classpath
121lookup, the <code>location</code> is used as is (no base is
122prepended). We use a Classloader to attempt to load the resource from
123the classpath. For example, if hello.jar is in the classpath and it
124contains <code>foo/bar/blat.dtd</code> it will resolve an entity whose
125<code>location</code> is <code>foo/bar/blat.dtd</code>. Of course, it
126will <em>not</em> resolve an entity whose <code>location</code> is
127<code>blat.dtd</code>.
128
129
130<h4>3a. Apache xml-commons resolver lookup</h4>
131
132<p>What happens next depends on whether the resolver library from
133xml-commons is available on the classpath. If so, we defer all
134further attempts at resolving to it. The resolver library supports
135extremely sophisticated functionality like URL rewriting and so on,
136which can be accessed by making the appropriate entries in external
137catalog files (XMLCatalog does not yet provide inline support for all
138of the entries defined in the <a
139href="http://oasis-open.org/committees/entity/spec-2001-08-06.html">OASIS
140standard</a>).</p>
141
142<h4>3. URL-space lookup</h4>
143
144<p>Finally, we attempt to make a URL out of the <code>location</code>.
145At first this may seem like this would defeat the purpose of
146XMLCatalogs -- why go back out to the internet? But in fact, this can
147be used to (in a sense) implement HTTP redirects, substituting one URL
148for another. The mapped-to URL might also be served by a local web
149server. If the URL resolves to a valid and readable resource, we are
150done. Otherwise, we give up. In this case, the XML processor will
151perform its normal resolution algorithm. Depending on the processor
152configuration, further resolution failures may or may not result in
153fatal (i.e. build-ending) errors.</p>
154
155<h3>XMLCatalog attributes</h3>
156<table border="1" cellpadding="2" cellspacing="0">
157 <tr>
158 <td valign="top"><b>Attribute</b></td>
159 <td valign="top"><b>Description</b></td>
160 <td align="center" valign="top"><b>Required</b></td>
161 </tr>
162 <tr>
163 <td valign="top">id</td>
164 <td valign="top">a unique name for an XMLCatalog, used for referencing
165the
166 XMLCatalog's contents from another XMLCatalog</td>
167 <td valign="top" align="center">No</td>
168 </tr>
169 <tr>
170 <td valign="top">refid</td>
171 <td valign="top">the <code>id</code> of another XMLCatalog whose
172contents
173 you would like to be used for this XMLCatalog</td>
174 <td valign="top" align="center">No</td>
175 </tr>
176</table>
177
178<h3>XMLCatalog nested elements</h3>
179<h4>dtd/entity</h4>
180<p>The <code>dtd</code> and <code>entity</code> elements used to specify
181XMLCatalogs are identical in their structure</p>
182<table border="1" cellpadding="2" cellspacing="0">
183 <tr>
184 <td valign="top"><b>Attribute</b></td>
185 <td valign="top"><b>Description</b></td>
186 <td align="center" valign="top"><b>Required</b></td>
187 </tr>
188 <tr>
189 <td valign="top">publicId</td>
190 <td valign="top">The public identifier used when defining a dtd or
191entity,
192 e.g. <code>&quot;-//Sun Microsystems, Inc.//DTD Web Application
1932.2//EN&quot;</code>
194 </td>
195 <td valign="top" align="center">Yes</td>
196 </tr>
197 <tr>
198 <td valign="top">location</td>
199 <td valign="top">The location of the local replacement to be used for
200the public identifier specified. This may be specified as a file name,
201resource name found on the classpath, or a URL. Relative paths will
202be resolved according to the base, which by default is the Ant project
203basedir.
204 </td>
205 <td valign="top" align="center">Yes</td>
206 </tr>
207</table>
208<h4>classpath</h4>
209<p>The classpath to use for <a href="#ResolverAlgorithm">entity
210resolution</a>. The nested <code>&lt;classpath&gt;</code> is a
211<a href="../using.html#path">path</a>-like structure.</p>
212<h4>catalogpath</h4>
213<p>
214The nested <code>catalogpath</code> element is a <a
215href="../using.html#path">path</a>-like structure listing catalog files to
216search. All files in this path are assumed to be OASIS catalog files, in
217either
218<a href="http://oasis-open.org/committees/entity/background/9401.html">
219plain text format</a> or <a
220href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
221XML format</a>. Entries specifying nonexistent files will be ignored. If the
222resolver library from xml-commons is not available in the classpath, all
223<code>catalogpaths</code> will be ignored and a warning will be logged.
224</p>
225<h3>Examples</h3>
226<p>Set up an XMLCatalog with a single dtd referenced locally in a user's
227home
228directory:</p>
229<blockquote><pre>
230 &lt;xmlcatalog&gt;
231 &lt;dtd
232 publicId=&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
233 location=&quot;/home/dion/downloads/docbook/docbookx.dtd&quot;/&gt;
234 &lt;/xmlcatalog&gt;
235</pre></blockquote>
236<p>Set up an XMLCatalog with a multiple dtds to be found either in the
237filesystem (relative to the Ant project basedir) or in the classpath:
238</p>
239<blockquote><pre>
240 &lt;xmlcatalog id=&quot;commonDTDs&quot;&gt;
241 &lt;dtd
242 publicId=&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
243 location=&quot;docbook/docbookx.dtd&quot;/&gt;
244 &lt;dtd
245 publicId=&quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&quot;
246 location=&quot;web-app_2_2.dtd&quot;/&gt;
247 &lt;/xmlcatalog&gt;
248</pre></blockquote>
249
250<p>Set up an XMLCatalog with a combination of DTDs and entities as
251well as a nested XMLCatalog and external catalog files in both
252formats:</p>
253
254<blockquote><pre>
255 &lt;xmlcatalog id=&quot;allcatalogs&quot;&gt;
256 &lt;dtd
257 publicId=&quot;-//ArielPartners//DTD XML Article V1.0//EN&quot;
258 location=&quot;com/arielpartners/knowledgebase/dtd/article.dtd&quot;/&gt;
259 &lt;entity
260 publicId=&quot;LargeLogo&quot;
261 location=&quot;com/arielpartners/images/ariel-logo-large.gif&quot;/&gt;
262 &lt;xmlcatalog refid="commonDTDs"/&gt;
263 &lt;catalogpath&gt;
264 &lt;pathelement location="/etc/sgml/catalog"/&gt;
265 &lt;fileset
266 dir=&quot;/anetwork/drive&quot;
267 includes=&quot;**/catalog&quot;/&gt;
268 &lt;fileset
269 dir=&quot;/my/catalogs&quot;
270 includes=&quot;**/catalog.xml&quot;/&gt;
271 &lt;/catalogpath&gt;
272 &lt;/xmlcatalog&gt;
273 &lt;/xmlcatalog&gt;
274</pre></blockquote>
275<p>To reference the above XMLCatalog in an <code>xslt</code> task:<p>
276<blockquote><pre>
277 &lt;xslt basedir="${source.doc}"
278 destdir="${dest.xdocs}"
279 extension=".xml"
280 style="${source.xsl.converter.docbook}"
281 includes="**/*.xml"
282 force="true"&gt;
283 &lt;xmlcatalog refid=&quot;allcatalogs&quot;/&gt;
284 &lt;/xslt&gt;
285</pre></blockquote>
286
287<hr>
288<p align="center">Copyright &copy; 2002,2004 The Apache Software Foundation. All
289rights
290Reserved.</p>
291
292</body>
293</html>
Note: See TracBrowser for help on using the repository browser.