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.

xmlproperty.html 9.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  18. <title>XmlProperty Task</title>
  19. </head>
  20. <body>
  21. <h2 id="xmlproperty">XmlProperty</h2>
  22. <h3>Description</h3>
  23. <p>
  24. Loads property values from a well-formed xml file. There are no other restrictions
  25. than "well-formed". You can choose the layout you want. For example this XML property file:
  26. <pre>
  27. &lt;root&gt;
  28. &lt;properties&gt;
  29. &lt;foo&gt;bar&lt;/foo&gt;
  30. &lt;/properties&gt;
  31. &lt;/root&gt;
  32. </pre>
  33. is roughly equivalent to this Java property file:
  34. <pre>
  35. root.properties.foo = bar
  36. </pre>
  37. <p>
  38. By default, this load
  39. does <em>no</em> processing of the input. In particular, unlike the
  40. <a href="property.html">Property task</a>, property references
  41. (i.e., <samp>${foo}</samp>) are not resolved.
  42. <p>
  43. <h3 id="semanticAttributes">Semantic Attributes</h3>
  44. Input processing can be enabled by using the <b>semanticAttributes</b>
  45. attribute. If this attribute is set to <i>true</i> (its default is
  46. <i>false</i>), the following processing occurs as the input XML file
  47. is loaded:
  48. <ul>
  49. <li>Property references are resolved.</li>
  50. <li>The following attributes are treated differently:
  51. <ul>
  52. <li><b>id</b>: The property is associated with the given id value.</li>
  53. <li><b>location</b>: The property is treated as a file location</li>
  54. <li><b>refid</b>: The property is set to the value of the
  55. referenced property.</li>
  56. <li><b>value</b>: The property is set to the value indicated.</li>
  57. </ul>
  58. </li>
  59. <li><a href="../using.html#path">Path-like Structures</a> can be defined
  60. by use of the following attributes:
  61. <ul>
  62. <li><b>pathid</b>: The given id is used to identify a path. The
  63. nested XML tag name is ignored. Child elements can be used
  64. (XML tag names are ignored) to identify elements of the path.</li>
  65. </ul>
  66. </li>
  67. </ul>
  68. <p>
  69. For example, with semantic attribute processing enabled, this XML property
  70. file:
  71. </p>
  72. <pre>
  73. &lt;root&gt;
  74. &lt;properties&gt;
  75. &lt;foo location="bar"/&gt;
  76. &lt;quux&gt;${root.properties.foo}&lt;/quux&gt;
  77. &lt;/properties&gt;
  78. &lt;/root&gt;
  79. </pre>
  80. is roughly equivalent to the following fragments in a build.xml file:
  81. <pre>
  82. &lt;property name="root.properties.foo" location="bar"/&gt;
  83. &lt;property name="root.properties.quux" value="${root.properties.foo}"/&gt;
  84. </pre>
  85. <h3>Parameters</h3>
  86. <table>
  87. <tr>
  88. <td valign="top"><b>Attribute</b></td>
  89. <td valign="top"><b>Description</b></td>
  90. <td align="center" valign="top"><b>Required</b></td>
  91. </tr>
  92. <tr>
  93. <td valign="top">file</td>
  94. <td valign="top">The XML file to parse.</td>
  95. <td valign="top" align="center">Yes, or a nested resource collection.</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">prefix</td>
  99. <td valign="top">The prefix to prepend to each property</td>
  100. <td valign="top" align="center">No</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">keepRoot</td>
  104. <td valign="top">Keep the xml root tag as the
  105. first value in the property name.</td>
  106. <td valign="top" align="center">No, default is <i>true</i>.</td>
  107. </tr>
  108. <tr>
  109. <td valign="top">validate</td>
  110. <td valign="top">Validate the input file (e.g. by a DTD). Otherwise the XML must only be well-formed.</td>
  111. <td valign="top" align="center">No, default is <i>false</i>.</td>
  112. </tr>
  113. <tr>
  114. <td valign="top">collapseAttributes</td>
  115. <td valign="top">Treat attributes as nested elements.</td>
  116. <td valign="top" align="center">No, default is <i>false</i>.</td>
  117. </tr>
  118. <tr>
  119. <td valign="top">semanticAttributes</td>
  120. <td valign="top">Enable special handling of certain attribute names.
  121. See the <a href="#semanticAttributes">Semantic Attributes</a>
  122. section for more information.</td>
  123. <td valign="top" align="center">No, default is <i>false</i>.</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">includeSemanticAttribute</td>
  127. <td valign="top">Include the semantic attribute name
  128. as part of the property name. Ignored if
  129. <i>semanticAttributes</i> is not set to <i>true</i>.
  130. See the <a href="#semanticAttributes">Semantic Attributes</a>
  131. section for more information.</td>
  132. <td valign="top" align="center">No, default is <i>false</i>.</td>
  133. </tr>
  134. <tr>
  135. <td valign="top">rootDirectory</td>
  136. <td valign="top">The directory to use for resolving file references. Ignored
  137. if <i>semanticAttributes</i> is not set to <i>true</i>.</td>
  138. <td valign="top" align="center">No, default is <code>${basedir}</code>.</td>
  139. </tr>
  140. <tr>
  141. <td valign="top">delimiter</td>
  142. <td valign="top">Delimiter for splitting multiple values.<br><em>since Apache Ant 1.7.1</em></td>
  143. <td valign="top" align="center">No, defaults to comma</td>
  144. </tr>
  145. </table>
  146. <h3 id="nested">Nested Elements</h3>
  147. <h4>xmlcatalog</h4>
  148. <p>The <a href="../Types/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a>
  149. element is used to perform entity resolution.</p>
  150. <h4>any <a href="../Types/resources.html">resource</a> or single element
  151. resource collection</h4>
  152. <p>The specified resource will be used as input.</p>
  153. <h3 id="examples">Examples</h3>
  154. <h4>Non-semantic Attributes</h4>
  155. <p>Here is an example xml file that does not have any semantic attributes.</p>
  156. <pre>
  157. &lt;root-tag myattr="true"&gt;
  158. &lt;inner-tag someattr="val"&gt;Text&lt;/inner-tag&gt;
  159. &lt;a2&gt;&lt;a3&gt;&lt;a4&gt;false&lt;/a4&gt;&lt;/a3&gt;&lt;/a2&gt;
  160. &lt;/root-tag&gt;
  161. </pre>
  162. <h5>default loading</h5>
  163. <p>This entry in a build file:
  164. <pre> &lt;xmlproperty file="somefile.xml"/&gt;</pre>
  165. is equivalent to the following properties:
  166. <pre>
  167. root-tag(myattr)=true
  168. root-tag.inner-tag=Text
  169. root-tag.inner-tag(someattr)=val
  170. root-tag.a2.a3.a4=false
  171. </pre>
  172. <h5>collapseAttributes=false</h5>
  173. <p>This entry in a build file:
  174. <pre> &lt;xmlproperty file="somefile.xml" collapseAttributes="true"/&gt;</pre>
  175. is equivalent to the following properties:
  176. <pre>
  177. root-tag.myattr=true
  178. root-tag.inner-tag=Text
  179. root-tag.inner-tag.someatt=val
  180. root-tag.a2.a3.a4=false
  181. </pre>
  182. <h5>keepRoot=false</h5>
  183. <p>This entry in a build file:
  184. <pre> &lt;xmlproperty file="somefile.xml" keepRoot="false"/&gt;</pre>
  185. is equivalent to the following properties:
  186. <pre>
  187. inner-tag=Text
  188. inner-tag(someattr)=val
  189. a2.a3.a4=false
  190. </pre>
  191. <h4>Semantic Attributes</h4>
  192. <p>Here is an example xml file that has semantic attributes.</p>
  193. <pre>
  194. &lt;root-tag&gt;
  195. &lt;version value="0.0.1"/&gt;
  196. &lt;build folder="build"&gt;
  197. &lt;classes id="build.classes" location="${build.folder}/classes"/&gt;
  198. &lt;reference refid="build.classes"/&gt;
  199. &lt;/build&gt;
  200. &lt;compile&gt;
  201. &lt;classpath pathid="compile.classpath"&gt;
  202. &lt;pathelement location="${build.classes}"/&gt;
  203. &lt;/classpath&gt;
  204. &lt;/compile&gt;
  205. &lt;run-time&gt;
  206. &lt;jars&gt;*.jar&lt;/jars&gt;
  207. &lt;classpath pathid="run-time.classpath"&gt;
  208. &lt;path refid="compile.classpath"/&gt;
  209. &lt;pathelement path="${run-time.jars}"/&gt;
  210. &lt;/classpath&gt;
  211. &lt;/run-time&gt;
  212. &lt;/root-tag&gt;
  213. </pre>
  214. <h5>default loading (semanticAttributes=true)</h5>
  215. <p>This entry in a build file:
  216. <pre> &lt;xmlproperty file="somefile.xml" keepRoot="false"
  217. semanticAttributes="true"/&gt;</pre>
  218. is equivalent to the following entries in a build file:
  219. <pre>
  220. &lt;property name="version" value="0.0.1"/&gt;
  221. &lt;property name="build.folder" value="build"/&gt;
  222. &lt;property name="build.classes" location="${build.folder}/classes" id="build.classes"/&gt;
  223. &lt;property name="build.reference" refid="build.classes"/&gt;
  224. &lt;property name="run-time.jars" value="*.jar"/&gt;
  225. &lt;path id="compile.classpath"&gt;
  226. &lt;pathelement location="${build.classes}"/&gt;
  227. &lt;/path&gt;
  228. &lt;path id="run-time.classpath"&gt;
  229. &lt;path refid="compile.classpath"/&gt;
  230. &lt;pathelement path="${run-time.jars}"/&gt;
  231. &lt;/path&gt;
  232. </pre>
  233. <h5>includeSemanticAttribute="true"</h5>
  234. <p>This entry in a build file:
  235. <pre> &lt;xmlproperty file="somefile.xml"
  236. semanticAttributes="true" keepRoot="false"
  237. includeSemanticAttribute="true"/&gt;
  238. </pre>
  239. is equivalent to the following entries in a build file:
  240. <pre>
  241. &lt;property name="version.value" value="0.0.1"/&gt;
  242. &lt;property name="build.folder" value="build"/&gt;
  243. &lt;property name="build.classes.location" location="${build.folder}/classes"/&gt;
  244. &lt;property name="build.reference.refid" refid="build.classes"/&gt;
  245. &lt;property name="run-time.jars" value="*.jar"/&gt;
  246. &lt;path id="compile.classpath"&gt;
  247. &lt;pathelement location="${build.classes}"/&gt;
  248. &lt;/path&gt;
  249. &lt;path id="run-time.classpath"&gt;
  250. &lt;path refid="compile.classpath"/&gt;
  251. &lt;pathelement path="${run-time.jars}"/&gt;
  252. &lt;/path&gt;
  253. </pre>
  254. </body>
  255. </html>