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
|
---|
14 | entities that are referenced in an XML document. Catalogs are
|
---|
15 | typically used to make web references to resources point to a locally
|
---|
16 | cached copy of the resource.</p>
|
---|
17 |
|
---|
18 | <p>This allows the XML Parser, XSLT Processor or other consumer of XML
|
---|
19 | documents
|
---|
20 | to efficiently allow a local substitution for a resource available on the
|
---|
21 | web.
|
---|
22 | </p>
|
---|
23 | <p><b>Note:</b> This task <em>uses, but does not depend on</em> external
|
---|
24 | libraries not included in the Ant distribution. See <a
|
---|
25 | href="../install.html#librarydependencies">Library Dependencies</a> for more
|
---|
26 | information.</p>
|
---|
27 | <p>This data type provides a catalog of resource locations based
|
---|
28 | on the <a
|
---|
29 | href="http://oasis-open.org/committees/entity/spec-2001-08-06.html">
|
---|
30 | OASIS "Open Catalog" standard</a>. The catalog entries are used
|
---|
31 | both for Entity resolution and URI resolution, in accordance with
|
---|
32 | the <code>org.xml.sax.EntityResolver</code> and <code>
|
---|
33 | javax.xml.transform.URIResolver</code> interfaces as defined
|
---|
34 | in the <a href="http://java.sun.com/xml/jaxp">Java API for XML
|
---|
35 | Processing (JAXP) Specification</a>.</p>
|
---|
36 | <p>For example, in a <code>web.xml</code> file, the DTD is referenced as:
|
---|
37 | <pre>
|
---|
38 | <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
|
---|
39 | "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
|
---|
40 | </pre>
|
---|
41 | The XML processor, without XMLCatalog support, would need to retrieve the
|
---|
42 | DTD from
|
---|
43 | the URL specified whenever validation of the document was required.
|
---|
44 | </p>
|
---|
45 | <p>This can be very time consuming during the build process,
|
---|
46 | especially where network throughput is limited. Alternatively, you
|
---|
47 | can do the following:
|
---|
48 | <ol>
|
---|
49 | <li>Copy <code>web-app_2_2.dtd</code> onto your local disk somewhere (either in the
|
---|
50 | filesystem or even embedded inside a jar or zip file on the classpath).</li>
|
---|
51 | <li>Create an <code><xmlcatalog></code> with a <code><dtd></code>
|
---|
52 | element 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
|
---|
54 | to the internet.</li>
|
---|
55 | </ol>
|
---|
56 | </p>
|
---|
57 | <p>XMLCatalogs can appear inside tasks
|
---|
58 | that 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
|
---|
60 | tasks,
|
---|
61 | e.g. XML Validation and XSLT Transformation. The XML Validate task
|
---|
62 | uses XMLCatalogs for entity resolution. The XSLT Transformation
|
---|
63 | task uses XMLCatalogs for both entity and URI resolution.</p>
|
---|
64 | <p>XMLCatalogs are specified as either a reference to another
|
---|
65 | XMLCatalog, defined previously in a build file, or as a list of
|
---|
66 | <code>dtd</code> or <code>entity</code> locations. In addition,
|
---|
67 | external catalog files may be specified in a nested <code>catalogpath</code> ,
|
---|
68 | but they will be ignored unless the resolver library from
|
---|
69 | xml-commons is available in the system classpath. <b>Due to backwards
|
---|
70 | incompatible changes in the resolver code after the release of
|
---|
71 | resolver 1.0, Ant will not support resolver.jar in version 1.0 - we
|
---|
72 | expect a resolver release 1.1 to happen before Ant 1.6 gets
|
---|
73 | released.</b> A separate classpath for entity resolution may be
|
---|
74 | specified inline via nested <code>classpath</code> elements; otherwise
|
---|
75 | the system classpath is used for this as well.</p>
|
---|
76 | <p>XMLCatalogs can also be nested inside other XMLCatalogs. For
|
---|
77 | example, a "superset" XMLCatalog could be made by including several
|
---|
78 | nested XMLCatalogs that referred to other, previously defined
|
---|
79 | XMLCatalogs.</p>
|
---|
80 | <p>Resource locations can be specified either in-line or in
|
---|
81 | external catalog file(s), or both. In order to use an external
|
---|
82 | catalog file, the xml-commons resolver library ("resolver.jar")
|
---|
83 | must be in your path. External catalog files may be either <a
|
---|
84 | href="http://oasis-open.org/committees/entity/background/9401.html">
|
---|
85 | plain text format</a> or <a
|
---|
86 | href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
|
---|
87 | XML format</a>. If the xml-commons resolver library is not found in the
|
---|
88 | classpath, external catalog files, specified in <code>catalogpath</code>,
|
---|
89 | will be ignored and a warning
|
---|
90 | will be logged. In this case, however, processing of inline entries will
|
---|
91 | proceed normally.</p>
|
---|
92 | <p>Currently, only <code><dtd></code> and
|
---|
93 | <code><entity></code> elements may be specified inline; these
|
---|
94 | roughly correspond to OASIS catalog entry types <code>PUBLIC</code> and
|
---|
95 | <code>URI</code> respectively. By contrast, external catalog files
|
---|
96 | may 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 |
|
---|
101 | When an entity, DTD, or URI is looked up by the XML processor, the
|
---|
102 | XMLCatalog searches its list of entries to see if any match. That is,
|
---|
103 | it attempts to match the <code>publicId</code> attribute of each entry
|
---|
104 | with the PublicID or URI of the entity to be resolved. Assuming a
|
---|
105 | matching 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
|
---|
110 | the <code>location</code> is a relative path, the ant project basedir
|
---|
111 | attribute is used as the base directory. If the <code>location</code>
|
---|
112 | specifies an absolute path, it is used as is. Once we have an
|
---|
113 | absolute path in hand, we check to see if a valid and readable file
|
---|
114 | exists at that path. If so, we are done. If not, we proceed to the
|
---|
115 | next step.</p>
|
---|
116 |
|
---|
117 | <h4>2. Classpath lookup</h4>
|
---|
118 |
|
---|
119 | <p>The <code>location</code> is next looked up in the classpath.
|
---|
120 | Recall that jar files are merely fancy zip files. For classpath
|
---|
121 | lookup, the <code>location</code> is used as is (no base is
|
---|
122 | prepended). We use a Classloader to attempt to load the resource from
|
---|
123 | the classpath. For example, if hello.jar is in the classpath and it
|
---|
124 | contains <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
|
---|
126 | will <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
|
---|
133 | xml-commons is available on the classpath. If so, we defer all
|
---|
134 | further attempts at resolving to it. The resolver library supports
|
---|
135 | extremely sophisticated functionality like URL rewriting and so on,
|
---|
136 | which can be accessed by making the appropriate entries in external
|
---|
137 | catalog files (XMLCatalog does not yet provide inline support for all
|
---|
138 | of the entries defined in the <a
|
---|
139 | href="http://oasis-open.org/committees/entity/spec-2001-08-06.html">OASIS
|
---|
140 | standard</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>.
|
---|
145 | At first this may seem like this would defeat the purpose of
|
---|
146 | XMLCatalogs -- why go back out to the internet? But in fact, this can
|
---|
147 | be used to (in a sense) implement HTTP redirects, substituting one URL
|
---|
148 | for another. The mapped-to URL might also be served by a local web
|
---|
149 | server. If the URL resolves to a valid and readable resource, we are
|
---|
150 | done. Otherwise, we give up. In this case, the XML processor will
|
---|
151 | perform its normal resolution algorithm. Depending on the processor
|
---|
152 | configuration, further resolution failures may or may not result in
|
---|
153 | fatal (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
|
---|
165 | the
|
---|
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
|
---|
172 | contents
|
---|
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
|
---|
181 | XMLCatalogs 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
|
---|
191 | entity,
|
---|
192 | e.g. <code>"-//Sun Microsystems, Inc.//DTD Web Application
|
---|
193 | 2.2//EN"</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
|
---|
200 | the public identifier specified. This may be specified as a file name,
|
---|
201 | resource name found on the classpath, or a URL. Relative paths will
|
---|
202 | be resolved according to the base, which by default is the Ant project
|
---|
203 | basedir.
|
---|
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
|
---|
210 | resolution</a>. The nested <code><classpath></code> is a
|
---|
211 | <a href="../using.html#path">path</a>-like structure.</p>
|
---|
212 | <h4>catalogpath</h4>
|
---|
213 | <p>
|
---|
214 | The nested <code>catalogpath</code> element is a <a
|
---|
215 | href="../using.html#path">path</a>-like structure listing catalog files to
|
---|
216 | search. All files in this path are assumed to be OASIS catalog files, in
|
---|
217 | either
|
---|
218 | <a href="http://oasis-open.org/committees/entity/background/9401.html">
|
---|
219 | plain text format</a> or <a
|
---|
220 | href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
|
---|
221 | XML format</a>. Entries specifying nonexistent files will be ignored. If the
|
---|
222 | resolver 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
|
---|
227 | home
|
---|
228 | directory:</p>
|
---|
229 | <blockquote><pre>
|
---|
230 | <xmlcatalog>
|
---|
231 | <dtd
|
---|
232 | publicId="-//OASIS//DTD DocBook XML V4.1.2//EN"
|
---|
233 | location="/home/dion/downloads/docbook/docbookx.dtd"/>
|
---|
234 | </xmlcatalog>
|
---|
235 | </pre></blockquote>
|
---|
236 | <p>Set up an XMLCatalog with a multiple dtds to be found either in the
|
---|
237 | filesystem (relative to the Ant project basedir) or in the classpath:
|
---|
238 | </p>
|
---|
239 | <blockquote><pre>
|
---|
240 | <xmlcatalog id="commonDTDs">
|
---|
241 | <dtd
|
---|
242 | publicId="-//OASIS//DTD DocBook XML V4.1.2//EN"
|
---|
243 | location="docbook/docbookx.dtd"/>
|
---|
244 | <dtd
|
---|
245 | publicId="-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
|
---|
246 | location="web-app_2_2.dtd"/>
|
---|
247 | </xmlcatalog>
|
---|
248 | </pre></blockquote>
|
---|
249 |
|
---|
250 | <p>Set up an XMLCatalog with a combination of DTDs and entities as
|
---|
251 | well as a nested XMLCatalog and external catalog files in both
|
---|
252 | formats:</p>
|
---|
253 |
|
---|
254 | <blockquote><pre>
|
---|
255 | <xmlcatalog id="allcatalogs">
|
---|
256 | <dtd
|
---|
257 | publicId="-//ArielPartners//DTD XML Article V1.0//EN"
|
---|
258 | location="com/arielpartners/knowledgebase/dtd/article.dtd"/>
|
---|
259 | <entity
|
---|
260 | publicId="LargeLogo"
|
---|
261 | location="com/arielpartners/images/ariel-logo-large.gif"/>
|
---|
262 | <xmlcatalog refid="commonDTDs"/>
|
---|
263 | <catalogpath>
|
---|
264 | <pathelement location="/etc/sgml/catalog"/>
|
---|
265 | <fileset
|
---|
266 | dir="/anetwork/drive"
|
---|
267 | includes="**/catalog"/>
|
---|
268 | <fileset
|
---|
269 | dir="/my/catalogs"
|
---|
270 | includes="**/catalog.xml"/>
|
---|
271 | </catalogpath>
|
---|
272 | </xmlcatalog>
|
---|
273 | </xmlcatalog>
|
---|
274 | </pre></blockquote>
|
---|
275 | <p>To reference the above XMLCatalog in an <code>xslt</code> task:<p>
|
---|
276 | <blockquote><pre>
|
---|
277 | <xslt basedir="${source.doc}"
|
---|
278 | destdir="${dest.xdocs}"
|
---|
279 | extension=".xml"
|
---|
280 | style="${source.xsl.converter.docbook}"
|
---|
281 | includes="**/*.xml"
|
---|
282 | force="true">
|
---|
283 | <xmlcatalog refid="allcatalogs"/>
|
---|
284 | </xslt>
|
---|
285 | </pre></blockquote>
|
---|
286 |
|
---|
287 | <hr>
|
---|
288 | <p align="center">Copyright © 2002,2004 The Apache Software Foundation. All
|
---|
289 | rights
|
---|
290 | Reserved.</p>
|
---|
291 |
|
---|
292 | </body>
|
---|
293 | </html>
|
---|