You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

antlib_namespaces.html 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html lang="en">
  3. <!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
  4. <head>
  5. <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  6. <title>Apache Ant - Antlib Namespaces</title>
  7. <link type="text/css" href="../../page.css" rel="stylesheet">
  8. <meta name="author" content="Antoine Levy-Lambert">
  9. <meta name="email" content="antoine@apache.org">
  10. </head>
  11. <body>
  12. <p class="navpath">
  13. <script src="../../breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
  14. </p>
  15. <div class="logobar">
  16. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  17. <tr>
  18. <td align="left"><img border="0" alt="Apache Ant site" src="../../images/group-logo.gif"></td>
  19. <td align="center" width="100%"><img alt="Apache Ant logo" border="0" src="../../images/project-logo.gif"></td>
  20. <td align="right">
  21. <form target="_blank" onsubmit="q.value = query.value + ' site:ant.apache.org'" action="http://www.google.com/search" method="get">
  22. <table summary="search" border="0" cellspacing="0" cellpadding="0" bgcolor="#4C6C8F">
  23. <tr>
  24. <td colspan="3"><img height="10" width="1" alt="" src="../../images/spacer.gif"></td>
  25. </tr>
  26. <tr>
  27. <td><img height="1" width="1" alt="" src="../../images/spacer.gif"></td>
  28. <td nowrap="nowrap" class="searchcaption">
  29. <input name="q" type="hidden">
  30. <input size="15" id="query" type="text">
  31. <img height="1" width="5" alt="" src="../../images/spacer.gif">
  32. <input name="Search" value="Search" type="submit">
  33. <br>
  34. the Apache Ant site
  35. </td>
  36. <td><img height="1" width="1" alt="" src="../../images/spacer.gif"></td>
  37. </tr>
  38. <tr>
  39. <td><img alt="" border="0" height="10" width="9" src="../../images/search-left.gif"></td>
  40. <td><img height="1" width="1" alt="" src="../../images/spacer.gif"></td>
  41. <td><img alt="" border="0" height="10" width="9" src="../../images/search-right.gif"></td>
  42. </tr>
  43. </table>
  44. </form>
  45. </td>
  46. </tr>
  47. </table>
  48. </div>
  49. <div class="tab">
  50. <table summary="tab bar" border="0" cellpadding="0" cellspacing="0">
  51. <tr>
  52. <td width="5"><img alt="" height="8" width="8" src="../../images/spacer.gif"></td><td valign="bottom">
  53. <table summary="non selected tab" style="height: 1.4em" border="0" cellpadding="0" cellspacing="0">
  54. <tr>
  55. <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>
  56. </tr>
  57. </table>
  58. </td>
  59. <td width="5"><img alt="" height="8" width="8" src="../../images/spacer.gif"></td><td valign="bottom">
  60. <table summary="non selected tab" style="height: 1.4em" border="0" cellpadding="0" cellspacing="0">
  61. <tr>
  62. <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>
  63. </tr>
  64. </table>
  65. </td>
  66. </tr>
  67. </table>
  68. </div>
  69. <div class="bluebar"></div>
  70. <div class="menucontainer">
  71. <div class="menu">
  72. <ul>
  73. </ul>
  74. </div>
  75. <img style="float: left" height="10" width="10" border="0" alt="" src="../../images/menu-left.gif">
  76. <img style="float: right" height="10" width="10" border="0" alt="" src="../../images/menu-right.gif">
  77. </div>
  78. <div class="lightbluebar">&nbsp;</div>
  79. <div class="main">
  80. <div class="content">
  81. <h1 class="title">Antlib Namespaces</h1>
  82. <h3 class="section">
  83. <a name="J.Pietschmann 03.05.2003 17:25"></a>
  84. J.Pietschmann 03.05.2003 17:25
  85. </h3>
  86. <p>
  87. Nicola Ken Barozzi wrote:
  88. &lt; This seems interesting, and brings up what XML namespaces can be used for.
  89. </p>
  90. <p>
  91. XML namespaces are indented to disambiguate short local element
  92. and attribute names. Any sematic associated to XML namespaces
  93. beside this has to be weighted carefully.
  94. </p>
  95. <p>
  96. Lets take an example. There are two projects, Foo and Bar,
  97. each providing a task, lets call them &lt;foo&gt; and &lt;bar&gt;
  98. respectively. Both tasks take a &lt;part&gt; child, by coincidence.
  99. Of course, because the projects act uncoordinated, the &lt;part&gt;
  100. child element has a different semantic. In order to make this
  101. clearer, let's say the Foo &lt;part&gt; takes an optional &lt;mumble&gt;
  102. child while the Bar &lt;part&gt; takes three mandatory &lt;xonx&gt;
  103. children.
  104. </p>
  105. <p>
  106. Someone finds both the &lt;foo&gt; and the &lt;bar&gt; task exciting and
  107. wants to use both in an Ant build file. No problem so far:
  108. because ot the way Ant elements get their child elements and
  109. create associated Java objects, this should work.
  110. Now said someone got a super-duper schema directed XML editor
  111. and wants to use it for editing the build.xml file. He asks
  112. all projects for a schema (DTD, XSD, RNG, whatever) for this
  113. purpose and merges them in order to get a schema for his build
  114. file. At this point the two &lt;part&gt; elements are likely to clash
  115. (at least for DTDs, where element names are global). While
  116. it is possible to merge the content models so that &lt;part&gt; now
  117. takes either an optional &lt;mumble&gt; or three &lt;xonx&gt; children, this
  118. would allow the user to put &lt;xonx&gt; children into the &lt;part&gt; of
  119. the &lt;foo&gt; task. This is only a minor inconvenience for most
  120. people, but an unthinkable horror for true purists.
  121. </p>
  122. <p>
  123. Introduce namespaces: the Foo projects names its namespace
  124. "http://www.fooproject.org/anttask" while the Bar project uses
  125. "URI:bar" or whatever. For the XML parser it is only really
  126. important that two different strings are used. You see, the
  127. longer the strings the less tha chance they will clash, and
  128. they probably won't clash if they start with the URLs of the
  129. project's homepages (the intent behind the recommendation to
  130. use URLs, because it's the closest thing to a global registry
  131. you can get short of actually creating a global registry).
  132. Anyway, because the expanded names of the &lt;part&gt; elements are
  133. now "{http://www.fooproject.org/anttask}part" and "{URI:bar}part"
  134. respectively they obviously no longer clash.
  135. BTW you can write this as
  136. </p>
  137. <pre class="code">
  138. &lt;target name=&quot;foo&quot;&gt;
  139. &lt;foo xmlns=&quot;http://www.fooproject.org/anttask&quot;&gt;
  140. &lt;part&gt;
  141. &lt;mumble&gt;
  142. &lt;/part&gt;
  143. &lt;/foo&gt;
  144. &lt;bar xmlns=&quot;URI:bar&quot;&gt;
  145. &lt;part&gt;&lt;xonx/&gt;&lt;xonx/&gt;&lt;xonx/&gt;&lt;/part&gt;
  146. &lt;/bar&gt;
  147. &lt;target&gt;
  148. </pre>
  149. <p>
  150. or as
  151. </p>
  152. <pre class="code">
  153. &lt;target name=&quot;foo&quot;
  154. xmlns:foo=&quot;http://www.fooproject.org/anttask&quot;
  155. xmlns:bar=&quot;URI:bar&quot;&gt;
  156. &lt;foo:foo&gt;
  157. &lt;foo:part&gt;
  158. &lt;foo:mumble&gt;
  159. &lt;/foo:part&gt;
  160. &lt;/foo:foo&gt;
  161. &lt;bar:bar&gt;
  162. &lt;bar:part&gt;&lt;bar:xonx/&gt;&lt;bar:xonx/&gt;&lt;bar:xonx/&gt;&lt;/bar:part&gt;
  163. &lt;/bar:bar&gt;
  164. &lt;target&gt;
  165. </pre>
  166. <p>
  167. take your pick (if you think the "foo" and "bar" prefixes are too
  168. long, use "a" and "b" instead, it doesn't matter).
  169. </p>
  170. <p>
  171. So far, the namespace names should only be different for different
  172. projects, so why is it dangerous to associate some semantic with it,
  173. like letting them point to a jar file? The problem is again that
  174. general purpose XML tools, like the above mentioned super-duper XML
  175. editor may associate their own semantics with the namespace, like
  176. how to auto-format certain elements. This information will be stored
  177. in some config files, and it requires that the namespace name is
  178. the same until the semantics of the elements in it have changed
  179. enough that it warrants assigning a new namespace name.
  180. </p>
  181. <p>
  182. Summary:
  183. </p>
  184. <ol>
  185. <li>
  186. XML namespaces are there to facilitate aggregation of XML adhering
  187. to schemas (content models) of different, uncoordinated origin.
  188. </li><li>
  189. XML Namespaces should be used in a way that no end user action
  190. can result in two namespace names becoming unintentionally the
  191. same.
  192. </li><li>
  193. XML Namespace names should preferably be assigned by the people
  194. or project which specifies the semantics of the XML elemnets and
  195. attributes therein.
  196. </li><li>
  197. XML Namespace names should be kept unchanged until a change of
  198. the semantic of the elements warrants a change.
  199. </li><li>
  200. Good tools should not monopolize XML namespace syntax for its
  201. own semantics.
  202. </li>
  203. </ol>
  204. <p>
  205. The schema directed editor should provide an example hoe tools
  206. can take advantage of XML namespaces: use them as a key into a
  207. DB/config to get it's own associated semantic.
  208. In particular for Ant/Antlib I can imagine that each library
  209. provides a factory object associated to the XML namespace for
  210. the library.
  211. </p>
  212. <p>
  213. The FOP parser uses such a two stage lookup: first the namespace
  214. is used to get a factory object from a hash table, then the factory
  215. is used with the local XML element name to create a Java object
  216. which is inserted into the FO tree. The hash table with the factories
  217. is initialized at startup, the associations between namespace name
  218. and factory class name is read from a Services file. Want to add
  219. a FOP extension? Get the default Services file, add a line with
  220. your namespace-to-factoryclassname mapping put it into the jar with
  221. all the classes and drop the jar as first into the classpath. If the
  222. user wants to use multiple extensions, well, edit the main Services
  223. instead, dead easy.
  224. </p>
  225. <p>
  226. HTH
  227. J.Pietschmann
  228. </p>
  229. </div>
  230. </div>
  231. <p class="copyright">
  232. Copyright &copy; 2000-2003&nbsp;The Apache Software Foundation. All rights reserved.
  233. <script type="text/javascript" language="JavaScript"><!--
  234. document.write(" - "+"Last Published: " + document.lastModified);
  235. // -->
  236. </script>
  237. </p>
  238. </body>
  239. </html>