mirror of
https://github.com/apache/ant.git
synced 2025-05-19 14:34:45 +00:00
260 lines
11 KiB
HTML
260 lines
11 KiB
HTML
|
|
||
|
|
||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
|
<html lang="en">
|
||
|
<!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
|
||
|
<head>
|
||
|
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||
|
<title>Apache Ant - Antlib Namespaces</title>
|
||
|
<link type="text/css" href="../../page.css" rel="stylesheet">
|
||
|
<meta name="author" content="Antoine Levy-Lambert">
|
||
|
<meta name="email" content="antoine@apache.org">
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
<p class="navpath">
|
||
|
<script src="../../breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
|
||
|
</p>
|
||
|
|
||
|
<div class="logobar">
|
||
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||
|
<tr>
|
||
|
<td align="left"><img border="0" alt="Apache Ant site" src="../../images/group-logo.gif"></td>
|
||
|
<td align="center" width="100%"><img alt="Apache Ant logo" border="0" src="../../images/project-logo.gif"></td>
|
||
|
<td align="right">
|
||
|
<form target="_blank" onsubmit="q.value = query.value + ' site:ant.apache.org'" action="http://www.google.com/search" method="get">
|
||
|
<table summary="search" border="0" cellspacing="0" cellpadding="0" bgcolor="#4C6C8F">
|
||
|
<tr>
|
||
|
<td colspan="3"><img height="10" width="1" alt="" src="../../images/spacer.gif"></td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td><img height="1" width="1" alt="" src="../../images/spacer.gif"></td>
|
||
|
<td nowrap="nowrap" class="searchcaption">
|
||
|
<input name="q" type="hidden">
|
||
|
<input size="15" id="query" type="text">
|
||
|
<img height="1" width="5" alt="" src="../../images/spacer.gif">
|
||
|
<input name="Search" value="Search" type="submit">
|
||
|
<br>
|
||
|
the Apache Ant site
|
||
|
</td>
|
||
|
<td><img height="1" width="1" alt="" src="../../images/spacer.gif"></td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td><img alt="" border="0" height="10" width="9" src="../../images/search-left.gif"></td>
|
||
|
<td><img height="1" width="1" alt="" src="../../images/spacer.gif"></td>
|
||
|
<td><img alt="" border="0" height="10" width="9" src="../../images/search-right.gif"></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</form>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
|
||
|
<div class="tab">
|
||
|
<table summary="tab bar" border="0" cellpadding="0" cellspacing="0">
|
||
|
<tr>
|
||
|
<td width="5"><img alt="" height="8" width="8" src="../../images/spacer.gif"></td><td valign="bottom">
|
||
|
<table summary="non selected tab" style="height: 1.4em" border="0" cellpadding="0" cellspacing="0">
|
||
|
<tr>
|
||
|
<td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="../../images/tab-left.gif"></td><td valign="middle" bgcolor="#B2C4E0"><a href="../../index.html"><font size="2" face="Arial, Helvetica, Sans-serif">Home</font></a></td><td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="../../images/tab-right.gif"></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</td>
|
||
|
<td width="5"><img alt="" height="8" width="8" src="../../images/spacer.gif"></td><td valign="bottom">
|
||
|
<table summary="non selected tab" style="height: 1.4em" border="0" cellpadding="0" cellspacing="0">
|
||
|
<tr>
|
||
|
<td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="../../images/tab-left.gif"></td><td valign="middle" bgcolor="#B2C4E0"><a href="../../projects/index.html"><font size="2" face="Arial, Helvetica, Sans-serif">Projects</font></a></td><td valign="top" width="5" bgcolor="#B2C4E0"><img height="5" width="5" alt="" src="../../images/tab-right.gif"></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
|
||
|
<div class="bluebar"></div>
|
||
|
|
||
|
<div class="menucontainer">
|
||
|
<div class="menu">
|
||
|
<ul>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<img style="float: left" height="10" width="10" border="0" alt="" src="../../images/menu-left.gif">
|
||
|
<img style="float: right" height="10" width="10" border="0" alt="" src="../../images/menu-right.gif">
|
||
|
</div>
|
||
|
<div class="lightbluebar"> </div>
|
||
|
<div class="main">
|
||
|
<div class="content">
|
||
|
<h1 class="title">Antlib Namespaces</h1>
|
||
|
<h3 class="section">
|
||
|
<a name="J.Pietschmann 03.05.2003 17:25"></a>
|
||
|
J.Pietschmann 03.05.2003 17:25
|
||
|
</h3>
|
||
|
<p>
|
||
|
Nicola Ken Barozzi wrote:
|
||
|
< This seems interesting, and brings up what XML namespaces can be used for.
|
||
|
</p>
|
||
|
<p>
|
||
|
XML namespaces are indented to disambiguate short local element
|
||
|
and attribute names. Any sematic associated to XML namespaces
|
||
|
beside this has to be weighted carefully.
|
||
|
</p>
|
||
|
<p>
|
||
|
|
||
|
Lets take an example. There are two projects, Foo and Bar,
|
||
|
each providing a task, lets call them <foo> and <bar>
|
||
|
respectively. Both tasks take a <part> child, by coincidence.
|
||
|
Of course, because the projects act uncoordinated, the <part>
|
||
|
child element has a different semantic. In order to make this
|
||
|
clearer, let's say the Foo <part> takes an optional <mumble>
|
||
|
child while the Bar <part> takes three mandatory <xonx>
|
||
|
children.
|
||
|
</p>
|
||
|
<p>
|
||
|
Someone finds both the <foo> and the <bar> task exciting and
|
||
|
wants to use both in an Ant build file. No problem so far:
|
||
|
because ot the way Ant elements get their child elements and
|
||
|
create associated Java objects, this should work.
|
||
|
Now said someone got a super-duper schema directed XML editor
|
||
|
and wants to use it for editing the build.xml file. He asks
|
||
|
all projects for a schema (DTD, XSD, RNG, whatever) for this
|
||
|
purpose and merges them in order to get a schema for his build
|
||
|
file. At this point the two <part> elements are likely to clash
|
||
|
(at least for DTDs, where element names are global). While
|
||
|
it is possible to merge the content models so that <part> now
|
||
|
takes either an optional <mumble> or three <xonx> children, this
|
||
|
would allow the user to put <xonx> children into the <part> of
|
||
|
the <foo> task. This is only a minor inconvenience for most
|
||
|
people, but an unthinkable horror for true purists.
|
||
|
</p>
|
||
|
<p>
|
||
|
Introduce namespaces: the Foo projects names its namespace
|
||
|
"http://www.fooproject.org/anttask" while the Bar project uses
|
||
|
"URI:bar" or whatever. For the XML parser it is only really
|
||
|
important that two different strings are used. You see, the
|
||
|
longer the strings the less tha chance they will clash, and
|
||
|
they probably won't clash if they start with the URLs of the
|
||
|
project's homepages (the intent behind the recommendation to
|
||
|
use URLs, because it's the closest thing to a global registry
|
||
|
you can get short of actually creating a global registry).
|
||
|
Anyway, because the expanded names of the <part> elements are
|
||
|
now "{http://www.fooproject.org/anttask}part" and "{URI:bar}part"
|
||
|
respectively they obviously no longer clash.
|
||
|
BTW you can write this as
|
||
|
</p>
|
||
|
<pre class="code">
|
||
|
<target name="foo">
|
||
|
<foo xmlns="http://www.fooproject.org/anttask">
|
||
|
<part>
|
||
|
<mumble>
|
||
|
</part>
|
||
|
</foo>
|
||
|
<bar xmlns="URI:bar">
|
||
|
<part><xonx/><xonx/><xonx/></part>
|
||
|
</bar>
|
||
|
<target>
|
||
|
</pre>
|
||
|
<p>
|
||
|
or as
|
||
|
</p>
|
||
|
<pre class="code">
|
||
|
<target name="foo"
|
||
|
xmlns:foo="http://www.fooproject.org/anttask"
|
||
|
xmlns:bar="URI:bar">
|
||
|
<foo:foo>
|
||
|
<foo:part>
|
||
|
<foo:mumble>
|
||
|
</foo:part>
|
||
|
</foo:foo>
|
||
|
<bar:bar>
|
||
|
<bar:part><bar:xonx/><bar:xonx/><bar:xonx/></bar:part>
|
||
|
</bar:bar>
|
||
|
<target>
|
||
|
</pre>
|
||
|
<p>
|
||
|
take your pick (if you think the "foo" and "bar" prefixes are too
|
||
|
long, use "a" and "b" instead, it doesn't matter).
|
||
|
</p>
|
||
|
<p>
|
||
|
So far, the namespace names should only be different for different
|
||
|
projects, so why is it dangerous to associate some semantic with it,
|
||
|
like letting them point to a jar file? The problem is again that
|
||
|
general purpose XML tools, like the above mentioned super-duper XML
|
||
|
editor may associate their own semantics with the namespace, like
|
||
|
how to auto-format certain elements. This information will be stored
|
||
|
in some config files, and it requires that the namespace name is
|
||
|
the same until the semantics of the elements in it have changed
|
||
|
enough that it warrants assigning a new namespace name.
|
||
|
</p>
|
||
|
<p>
|
||
|
|
||
|
Summary:
|
||
|
</p>
|
||
|
<ol>
|
||
|
<li>
|
||
|
XML namespaces are there to facilitate aggregation of XML adhering
|
||
|
to schemas (content models) of different, uncoordinated origin.
|
||
|
</li><li>
|
||
|
XML Namespaces should be used in a way that no end user action
|
||
|
can result in two namespace names becoming unintentionally the
|
||
|
same.
|
||
|
</li><li>
|
||
|
XML Namespace names should preferably be assigned by the people
|
||
|
or project which specifies the semantics of the XML elemnets and
|
||
|
attributes therein.
|
||
|
</li><li>
|
||
|
XML Namespace names should be kept unchanged until a change of
|
||
|
the semantic of the elements warrants a change.
|
||
|
</li><li>
|
||
|
Good tools should not monopolize XML namespace syntax for its
|
||
|
own semantics.
|
||
|
</li>
|
||
|
</ol>
|
||
|
<p>
|
||
|
The schema directed editor should provide an example hoe tools
|
||
|
can take advantage of XML namespaces: use them as a key into a
|
||
|
DB/config to get it's own associated semantic.
|
||
|
In particular for Ant/Antlib I can imagine that each library
|
||
|
provides a factory object associated to the XML namespace for
|
||
|
the library.
|
||
|
</p>
|
||
|
<p>
|
||
|
The FOP parser uses such a two stage lookup: first the namespace
|
||
|
is used to get a factory object from a hash table, then the factory
|
||
|
is used with the local XML element name to create a Java object
|
||
|
which is inserted into the FO tree. The hash table with the factories
|
||
|
is initialized at startup, the associations between namespace name
|
||
|
and factory class name is read from a Services file. Want to add
|
||
|
a FOP extension? Get the default Services file, add a line with
|
||
|
your namespace-to-factoryclassname mapping put it into the jar with
|
||
|
all the classes and drop the jar as first into the classpath. If the
|
||
|
user wants to use multiple extensions, well, edit the main Services
|
||
|
instead, dead easy.
|
||
|
</p>
|
||
|
<p>
|
||
|
HTH
|
||
|
J.Pietschmann
|
||
|
</p>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<p class="copyright">
|
||
|
Copyright © 2000-2003 The Apache Software Foundation. All rights reserved.
|
||
|
<script type="text/javascript" language="JavaScript"><!--
|
||
|
document.write(" - "+"Last Published: " + document.lastModified);
|
||
|
// -->
|
||
|
</script>
|
||
|
</p>
|
||
|
</body>
|
||
|
</html>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|