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.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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><a name="xmlproperty">XmlProperty</a></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. <a name="semanticAttributes">
  44. <h3>Semantic Attributes</h3>
  45. </a>
  46. Input processing can be enabled by using the <b>semanticAttributes</b>
  47. attribute. If this attribute is set to <i>true</i> (its default is
  48. <i>false</i>), the following processing occurs as the input XML file
  49. is loaded:
  50. <ul>
  51. <li>Property references are resolved.</li>
  52. <li>The following attributes are treated differently:
  53. <ul>
  54. <li><b>id</b>: The property is associated with the given id value.</li>
  55. <li><b>location</b>: The property is treated as a file location</li>
  56. <li><b>refid</b>: The property is set to the value of the
  57. referenced property.</li>
  58. <li><b>value</b>: The property is set to the value indicated.</li>
  59. </ul>
  60. </li>
  61. <li><a href="../using.html#path">Path-like Structures</a> can be defined
  62. by use of the following attributes:
  63. <ul>
  64. <li><b>pathid</b>: The given id is used to identify a path. The
  65. nested XML tag name is ignored. Child elements can be used
  66. (XML tag names are ignored) to identify elements of the path.</li>
  67. </ul>
  68. </li>
  69. </ul>
  70. <p>
  71. For example, with semantic attribute processing enabled, this XML property
  72. file:
  73. <pre>
  74. &lt;root&gt;
  75. &lt;properties&gt;
  76. &lt;foo location="bar"/&gt;
  77. &lt;quux&gt;${root.properties.foo}&lt;/quux&gt;
  78. &lt;/properties&gt;
  79. &lt;/root&gt;
  80. </pre>
  81. is roughly equivalent to the following fragments in a build.xml file:
  82. <pre>
  83. &lt;property name="root.properties.foo" location="bar"/&gt;
  84. &lt;property name="root.properties.quux" value="${root.properties.foo}"/&gt;
  85. </pre>
  86. </p>
  87. <h3>Parameters</h3>
  88. <table border="1" cellpadding="2" cellspacing="0">
  89. <tr>
  90. <td valign="top"><b>Attribute</b></td>
  91. <td valign="top"><b>Description</b></td>
  92. <td align="center" valign="top"><b>Required</b></td>
  93. </tr>
  94. <tr>
  95. <td valign="top">file</td>
  96. <td valign="top">The XML file to parse.</td>
  97. <td valign="top" align="center">Yes, or a nested resource collection.</td>
  98. </tr>
  99. <tr>
  100. <td valign="top">prefix</td>
  101. <td valign="top">The prefix to prepend to each property</td>
  102. <td valign="top" align="center">No</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">keepRoot</td>
  106. <td valign="top">Keep the xml root tag as the
  107. first value in the property name.</td>
  108. <td valign="top" align="center">No, default is <i>true</i>.</td>
  109. </tr>
  110. <tr>
  111. <td valign="top">validate</td>
  112. <td valign="top">Validate the input file (e.g. by a DTD). Otherwise the XML must only be well-formed.</td>
  113. <td valign="top" align="center">No, default is <i>false</i>.</td>
  114. </tr>
  115. <tr>
  116. <td valign="top">collapseAttributes</td>
  117. <td valign="top">Treat attributes as nested elements.</td>
  118. <td valign="top" align="center">No, default is <i>false</i>.</td>
  119. </tr>
  120. <tr>
  121. <td valign="top">semanticAttributes</td>
  122. <td valign="top">Enable special handling of certain attribute names.
  123. See the <a href="#semanticAttributes">Semantic Attributes</a>
  124. section for more information.</td>
  125. <td valign="top" align="center">No, default is <i>false</i>.</td>
  126. </tr>
  127. <tr>
  128. <td valign="top">includeSemanticAttribute</td>
  129. <td valign="top">Include the semantic attribute name
  130. as part of the property name. Ignored if
  131. <i>semanticAttributes</i> is not set to <i>true</i>.
  132. See the <a href="#semanticAttributes">Semantic Attributes</a>
  133. section for more information.</td>
  134. <td valign="top" align="center">No, default is <i>false</i>.</td>
  135. </tr>
  136. <tr>
  137. <td valign="top">rootDirectory</td>
  138. <td valign="top">The directory to use for resolving file references. Ignored
  139. if <i>semanticAttributes</i> is not set to <i>true</i>.</td>
  140. <td valign="top" align="center">No, default is <i>${basedir}</i>.</td>
  141. </tr>
  142. <tr>
  143. <td valign="top">delimiter</td>
  144. <td valign="top">Delimiter for splitting multiple values.<br><i>since Ant 1.7.1</i></td>
  145. <td valign="top" align="center">No, defaults to comma</td>
  146. </tr>
  147. </table>
  148. <h3><a name="nested">Nested Elements</a></h3>
  149. <h4>xmlcatalog</h4>
  150. <p>The <a href="../CoreTypes/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a>
  151. element is used to perform entity resolution.</p>
  152. <h4>any <a href="../CoreTypes/resources.html">resource</a> or single element
  153. resource collection</h4>
  154. <p>The specified resource will be used as input.</p>
  155. <a name="examples">
  156. <h3>Examples</h3>
  157. </a>
  158. <h4>Non-semantic Attributes</h4>
  159. <p>Here is an example xml file that does not have any semantic attributes.</p>
  160. <pre>
  161. &lt;root-tag myattr="true"&gt;
  162. &lt;inner-tag someattr="val"&gt;Text&lt;/inner-tag&gt;
  163. &lt;a2&gt;&lt;a3&gt;&lt;a4&gt;false&lt;/a4&gt;&lt;/a3&gt;&lt;/a2&gt;
  164. &lt;/root-tag&gt;
  165. </pre>
  166. <h5>default loading</h5>
  167. <p>This entry in a build file:
  168. <pre> &lt;xmlproperty file="somefile.xml"/&gt;</pre>
  169. is equivalent to the following properties:
  170. <pre>
  171. root-tag(myattr)=true
  172. root-tag.inner-tag=Text
  173. root-tag.inner-tag(someattr)=val
  174. root-tag.a2.a3.a4=false
  175. </pre>
  176. <h5>collapseAttributes=false</h5>
  177. <p>This entry in a build file:
  178. <pre> &lt;xmlproperty file="somefile.xml" collapseAttributes="true"/&gt;</pre>
  179. is equivalent to the following properties:
  180. <pre>
  181. root-tag.myattr=true
  182. root-tag.inner-tag=Text
  183. root-tag.inner-tag.someatt=val
  184. root-tag.a2.a3.a4=false
  185. </pre>
  186. <h5>keepRoot=false</h5>
  187. <p>This entry in a build file:
  188. <pre> &lt;xmlproperty file="somefile.xml" keepRoot="false"/&gt;</pre>
  189. is equivalent to the following properties:
  190. <pre>
  191. inner-tag=Text
  192. inner-tag(someattr)=val
  193. a2.a3.a4=false
  194. </pre>
  195. <h4>Semantic Attributes</h4>
  196. <p>Here is an example xml file that has semantic attributes.</p>
  197. <pre>
  198. &lt;root-tag&gt;
  199. &lt;version value="0.0.1"/&gt;
  200. &lt;build folder="build"&gt;
  201. &lt;classes id="build.classes" location="${build.folder}/classes"/&gt;
  202. &lt;reference refid="build.classes"/&gt;
  203. &lt;/build&gt;
  204. &lt;compile&gt;
  205. &lt;classpath pathid="compile.classpath"&gt;
  206. &lt;pathelement location="${build.classes}"/&gt;
  207. &lt;/classpath&gt;
  208. &lt;/compile&gt;
  209. &lt;run-time&gt;
  210. &lt;jars&gt;*.jar&lt;/jars&gt;
  211. &lt;classpath pathid="run-time.classpath"&gt;
  212. &lt;path refid="compile.classpath"/&gt;
  213. &lt;pathelement path="${run-time.jars}"/&gt;
  214. &lt;/classpath&gt;
  215. &lt;/run-time&gt;
  216. &lt;/root-tag&gt;
  217. </pre>
  218. <h5>default loading (semanticAttributes=true)</h5>
  219. <p>This entry in a build file:
  220. <pre> &lt;xmlproperty file="somefile.xml"
  221. semanticAttributes="true"/&gt;</pre>
  222. is equivalent to the following entries in a build file:
  223. <pre>
  224. &lt;property name="version" value="0.0.1"/&gt;
  225. &lt;property name="build.folder" value="build"/&gt;
  226. &lt;property name="build.classes" location="${build.folder}/classes" id="build.classes"/&gt;
  227. &lt;property name="build.reference" refid="build.classes"/&gt;
  228. &lt;property name="run-time.jars" value="*.jar/&gt;
  229. &lt;classpath id="compile.classpath"&gt;
  230. &lt;pathelement location="${build.classes}"/&gt;
  231. &lt;/classpath&gt;
  232. &lt;classpath id="run-time.classpath"&gt;
  233. &lt;path refid="compile.classpath"/&gt;
  234. &lt;pathelement path="${run-time.jars}"/&gt;
  235. &lt;/classpath&gt;
  236. </pre>
  237. <h5>includeSemanticAttribute="true"</h5>
  238. <p>This entry in a build file:
  239. <pre> &lt;xmlproperty file="somefile.xml"
  240. semanticAttributes="true"
  241. includeSemanticAttribute="true"/&gt;
  242. </pre>
  243. is equivalent to the following entries in a build file:
  244. <pre>
  245. &lt;property name="version.value" value="0.0.1"/&gt;
  246. &lt;property name="build.folder" value="build"/&gt;
  247. &lt;property name="build.classes.location" location="${build.folder}/classes"/&gt;
  248. &lt;property name="build.reference.refid" refid="build.location"/&gt;
  249. &lt;property name="run-time.jars" value="*.jar/&gt;
  250. &lt;classpath id="compile.classpath"&gt;
  251. &lt;pathelement location="${build.classes}"/&gt;
  252. &lt;/classpath&gt;
  253. &lt;classpath id="run-time.classpath"&gt;
  254. &lt;path refid="compile.classpath"/&gt;
  255. &lt;pathelement path="${run-time.jars}"/&gt;
  256. &lt;/classpath&gt;
  257. </pre>
  258. </body>
  259. </html>