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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <html>
  2. <head>
  3. <title>XmlProperty Task</title>
  4. </head>
  5. <body>
  6. <h2><a name="xmlproperty">XmlProperty</a></h2>
  7. <h3>Description</h3>
  8. <p>
  9. Loads property values from a valid xml file. This XML property file:
  10. <pre>
  11. &lt;root&gt;
  12. &lt;properties&gt;
  13. &lt;foo&gt;bar&lt;/foo&gt;
  14. &lt;/properties&gt;
  15. &lt;/root&gt;
  16. </pre>
  17. is roughly equivalent to this java property file:
  18. <pre>
  19. root.properties.foo = bar
  20. </pre>
  21. <p>
  22. By default, this load
  23. does <em>no</em> processing of the input. In particular, unlike the
  24. <a href="property.html">Property task</a>, property references
  25. (i.e., ${foo}) are not resolved.
  26. <p>
  27. <a name="semanticAttributes">
  28. <h3>Semantic Attributes</h3>
  29. </a>
  30. Input processing can be enabled by using the <b>semanticAttributes</b>
  31. attribute. If this attribute is set to <i>true</i> (its default is
  32. <i>false</i>), the following processing occurs as the input XML file
  33. is loaded:
  34. <ul>
  35. <li>Property references are resolved.</li>
  36. <li>The following attriubtes are treated differently:
  37. <ul>
  38. <li><b>id</b>: The property is associated with the given id value.</li>
  39. <li><b>location</b>: The property is treated as a file location</li>
  40. <li><b>refid</b>: The property is set to the value of the
  41. referenced property.</li>
  42. <li><b>value</b>: The property is set to the value indicated.</li>
  43. </ul>
  44. </li>
  45. <li><a href="../using.html#path">Path-like Structures</a> can be defined
  46. by use of the following attributes:
  47. <ul>
  48. <li><b>pathid</b>: The given id is used to identify a path. The
  49. nested XML tag name is ignored. Child elements can be used
  50. (XML tag names are ignored) to identify elements of the path.</li>
  51. </ul>
  52. </li>
  53. </ul>
  54. <p>
  55. For example, with semantic attribute processing enabled, this XML property
  56. file:
  57. <pre>
  58. &lt;root&gt;
  59. &lt;properties&gt;
  60. &lt;foo location="bar"/&gt;
  61. &lt;quux&gt;${root.properties.foo}&lt;/quux&gt;
  62. &lt;/properties&gt;
  63. &lt;/root&gt;
  64. </pre>
  65. is roughly equivalent to the following fragments in a build.xml file:
  66. <pre>
  67. &lt;property name="root.properties.foo" location="bar"/&gt;
  68. &lt;property name="root.properties.quux" value="${root.properties.foo}"/&gt;
  69. </pre>
  70. </p>
  71. <h3>Parameters</h3>
  72. <table border="1" cellpadding="2" cellspacing="0">
  73. <tr>
  74. <td valign="top"><b>Attribute</b></td>
  75. <td valign="top"><b>Description</b></td>
  76. <td align="center" valign="top"><b>Required</b></td>
  77. </tr>
  78. <tr>
  79. <td valign="top">file</td>
  80. <td valign="top">The XML file to parse.</td>
  81. <td valign="top" align="center">Yes</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">prefix</td>
  85. <td valign="top">The prefix to prepend to each property</td>
  86. <td valign="top" align="center">No</td>
  87. </tr>
  88. <tr>
  89. <td valign="top">keepRoot</td>
  90. <td valign="top">Keep the xml root tag as the
  91. first value in the property name.</td>
  92. <td valign="top" align="center">No, default is <i>true</i>.</td>
  93. </tr>
  94. <tr>
  95. <td valign="top">validate</td>
  96. <td valign="top">Validate the input file.</td>
  97. <td valign="top" align="center">No, default is <i>false</i>.</td>
  98. </tr>
  99. <tr>
  100. <td valign="top">collapseAttributes</td>
  101. <td valign="top">Treat attributes as nested elements.</td>
  102. <td valign="top" align="center">No, default is <i>false</i>.</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">semanticAttributes</td>
  106. <td valign="top">Enable special handling of certain attribute names.
  107. See the <a href="#semanticAttributes">Semantic Attributes</a>
  108. section for more information.</td>
  109. <td valign="top" align="center">No, default is <i>false</i>.</td>
  110. </tr>
  111. <tr>
  112. <td valign="top">includeSemanticAttribute</td>
  113. <td valign="top">Include the semantic attribute name
  114. as part of the property name. Ignored if
  115. <i>semanticAttributes</i> is not set to <i>true</i>.
  116. See the <a href="#semanticAttributes">Semantic Attributes</a>
  117. section for more information.</td>
  118. <td valign="top" align="center">No, default is <i>false</i>.</td>
  119. </tr>
  120. <tr>
  121. <td valign="top">rootDirectory</td>
  122. <td valign="top">The directory to use for resolving file references. Ignored
  123. if <i>semanticAttributes</i> is not set to <i>true</i>.</td>
  124. <td valign="top" align="center">No, default is <i>${basedir}</i>.</td>
  125. </tr>
  126. </table>
  127. <a name="examples">
  128. <h3>Examples</h3>
  129. </a>
  130. <h4>Non-semantic Attributes</h4>
  131. <p>Here is an example xml file that does not have any semantic attributes.</p>
  132. <pre>
  133. &lt;root-tag myattr="true"&gt;
  134. &lt;inner-tag someattr="val"&gt;Text&lt;/inner-tag&gt;
  135. &lt;a2&gt;&lt;a3&gt;&lt;a4&gt;false&lt;/a4&gt;&lt;/a3&gt;&lt;/a2&gt;
  136. &lt;/root-tag&gt;
  137. </pre>
  138. <h5>default loading</h5>
  139. <p>This entry in a build file:
  140. <pre> &lt;xmlproperty file="somefile.xml" /&gt;</pre>
  141. is equivalent to the following properties:
  142. <pre>
  143. root-tag(myattr)=true
  144. root-tag.inner-tag=Text
  145. root-tag.inner-tag(someattr)=val
  146. root-tag.a2.a3.a4=false
  147. </pre>
  148. <h5>collapseAttributes=false</h5>
  149. <p>This entry in a build file:
  150. <pre> &lt;xmlproperty file="somefile.xml" collapseAttributes="true"/&gt;</pre>
  151. is equivalent to the following properties:
  152. <pre>
  153. root-tag.myattr=true
  154. root-tag.inner-tag=Text
  155. root-tag.inner-tag.someatt=val
  156. root-tag.a2.a3.a4=false
  157. </pre>
  158. <h5>keepRoot=false</h5>
  159. <p>This entry in a build file:
  160. <pre> &lt;xmlproperty file="somefile.xml" keepRoot="false"/&gt;</pre>
  161. is equivalent to the following properties:
  162. <pre>
  163. inner-tag=Text
  164. inner-tag(someattr)=val
  165. a2.a3.a4=false
  166. </pre>
  167. <h4>Semantic Attributes</h4>
  168. <p>Here is an example xml file that has semantic attributes.</p>
  169. <pre>
  170. &lt;root-tag&gt;
  171. &lt;version value="0.0.1"/&gt;
  172. &lt;build folder="build"&gt;
  173. &lt;classes id="build.classes" location="${build.folder}/classes"/&gt;
  174. &lt;reference refid="build.classes"/&gt;
  175. &lt;/build&gt;
  176. &lt;compile&gt;
  177. &lt;classpath pathid="compile.classpath"&gt;
  178. &lt;pathelement location="${build.classes}"/&gt;
  179. &lt;/classpath&gt;
  180. &lt;/compile&gt;
  181. &lt;run-time&gt;
  182. &lt;jars&gt;*.jar&lt;/jars&gt;
  183. &lt;classpath pathid="run-time.classpath"&gt;
  184. &lt;path refid="compile.classpath"/&gt;
  185. &lt;pathelement path="${run-time.jars}"/&gt;
  186. &lt;/classpath&gt;
  187. &lt;/run-time&gt;
  188. &lt;/root-tag&gt;
  189. </pre>
  190. <h5>default loading (semanticAttributes=true)</h5>
  191. <p>This entry in a build file:
  192. <pre> &lt;xmlproperty file="somefile.xml"
  193. semanticAttributes="true"/&gt;</pre>
  194. is equivalent to the following entries in a build file:
  195. <pre>
  196. &lt;property name="version" value="0.0.1"/&gt;
  197. &lt;property name="build.folder" value="build"/&gt;
  198. &lt;property name="build.classes" location="${build.folder}/classes" id="build.classes"/&gt;
  199. &lt;property name="build.reference" refid="build.classes"/&gt;
  200. &lt;property name="run-time.jars" value="*.jar/&gt;
  201. &lt;classpath id="compile.classpath"&gt;
  202. &lt;pathelement location="${build.classes}"/&gt;
  203. &lt;/classpath&gt;
  204. &lt;classpath id="run-time.classpath"&gt;
  205. &lt;path refid="compile.classpath"/&gt;
  206. &lt;pathelement path="${run-time.jars}"/&gt;
  207. &lt;/classpath&gt;
  208. </pre>
  209. <h5>includeSemanticAttribute="true"</h5>
  210. <p>This entry in a build file:
  211. <pre> &lt;xmlproperty file="somefile.xml"
  212. semanticAttributes="true"
  213. includeSemanticAttribute="true"/&gt;
  214. </pre>
  215. is equivalent to the following entries in a build file:
  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.location"/&gt;
  221. &lt;property name="run-time.jars" value="*.jar/&gt;
  222. &lt;classpath id="compile.classpath"&gt;
  223. &lt;pathelement location="${build.classes}"/&gt;
  224. &lt;/classpath&gt;
  225. &lt;classpath id="run-time.classpath"&gt;
  226. &lt;path refid="compile.classpath"/&gt;
  227. &lt;pathelement path="${run-time.jars}"/&gt;
  228. &lt;/classpath&gt;
  229. </pre>
  230. <hr/>
  231. <p align="center">Copyright &copy; 2002 Apache Software Foundation. All rights
  232. Reserved.</p>
  233. </body>
  234. </html>