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 8.9 KiB

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