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