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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. <h3><a name="nested">Nested Elements</a></h3>
  129. <h4>xmlcatalog</h4>
  130. <p>The <a href="../CoreTypes/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a>
  131. element is used to perform entity resolution.</p>
  132. <a name="examples">
  133. <h3>Examples</h3>
  134. </a>
  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;
  142. </pre>
  143. <h5>default loading</h5>
  144. <p>This entry in a build file:
  145. <pre> &lt;xmlproperty file="somefile.xml"/&gt;</pre>
  146. is equivalent to the following properties:
  147. <pre>
  148. root-tag(myattr)=true
  149. root-tag.inner-tag=Text
  150. root-tag.inner-tag(someattr)=val
  151. root-tag.a2.a3.a4=false
  152. </pre>
  153. <h5>collapseAttributes=false</h5>
  154. <p>This entry in a build file:
  155. <pre> &lt;xmlproperty file="somefile.xml" collapseAttributes="true"/&gt;</pre>
  156. is equivalent to the following properties:
  157. <pre>
  158. root-tag.myattr=true
  159. root-tag.inner-tag=Text
  160. root-tag.inner-tag.someatt=val
  161. root-tag.a2.a3.a4=false
  162. </pre>
  163. <h5>keepRoot=false</h5>
  164. <p>This entry in a build file:
  165. <pre> &lt;xmlproperty file="somefile.xml" keepRoot="false"/&gt;</pre>
  166. is equivalent to the following properties:
  167. <pre>
  168. inner-tag=Text
  169. inner-tag(someattr)=val
  170. a2.a3.a4=false
  171. </pre>
  172. <h4>Semantic Attributes</h4>
  173. <p>Here is an example xml file that has semantic attributes.</p>
  174. <pre>
  175. &lt;root-tag&gt;
  176. &lt;version value="0.0.1"/&gt;
  177. &lt;build folder="build"&gt;
  178. &lt;classes id="build.classes" location="${build.folder}/classes"/&gt;
  179. &lt;reference refid="build.classes"/&gt;
  180. &lt;/build&gt;
  181. &lt;compile&gt;
  182. &lt;classpath pathid="compile.classpath"&gt;
  183. &lt;pathelement location="${build.classes}"/&gt;
  184. &lt;/classpath&gt;
  185. &lt;/compile&gt;
  186. &lt;run-time&gt;
  187. &lt;jars&gt;*.jar&lt;/jars&gt;
  188. &lt;classpath pathid="run-time.classpath"&gt;
  189. &lt;path refid="compile.classpath"/&gt;
  190. &lt;pathelement path="${run-time.jars}"/&gt;
  191. &lt;/classpath&gt;
  192. &lt;/run-time&gt;
  193. &lt;/root-tag&gt;
  194. </pre>
  195. <h5>default loading (semanticAttributes=true)</h5>
  196. <p>This entry in a build file:
  197. <pre> &lt;xmlproperty file="somefile.xml"
  198. semanticAttributes="true"/&gt;</pre>
  199. is equivalent to the following entries in a build file:
  200. <pre>
  201. &lt;property name="version" value="0.0.1"/&gt;
  202. &lt;property name="build.folder" value="build"/&gt;
  203. &lt;property name="build.classes" location="${build.folder}/classes" id="build.classes"/&gt;
  204. &lt;property name="build.reference" refid="build.classes"/&gt;
  205. &lt;property name="run-time.jars" value="*.jar/&gt;
  206. &lt;classpath id="compile.classpath"&gt;
  207. &lt;pathelement location="${build.classes}"/&gt;
  208. &lt;/classpath&gt;
  209. &lt;classpath id="run-time.classpath"&gt;
  210. &lt;path refid="compile.classpath"/&gt;
  211. &lt;pathelement path="${run-time.jars}"/&gt;
  212. &lt;/classpath&gt;
  213. </pre>
  214. <h5>includeSemanticAttribute="true"</h5>
  215. <p>This entry in a build file:
  216. <pre> &lt;xmlproperty file="somefile.xml"
  217. semanticAttributes="true"
  218. includeSemanticAttribute="true"/&gt;
  219. </pre>
  220. is equivalent to the following entries in a build file:
  221. <pre>
  222. &lt;property name="version.value" value="0.0.1"/&gt;
  223. &lt;property name="build.folder" value="build"/&gt;
  224. &lt;property name="build.classes.location" location="${build.folder}/classes"/&gt;
  225. &lt;property name="build.reference.refid" refid="build.location"/&gt;
  226. &lt;property name="run-time.jars" value="*.jar/&gt;
  227. &lt;classpath id="compile.classpath"&gt;
  228. &lt;pathelement location="${build.classes}"/&gt;
  229. &lt;/classpath&gt;
  230. &lt;classpath id="run-time.classpath"&gt;
  231. &lt;path refid="compile.classpath"/&gt;
  232. &lt;pathelement path="${run-time.jars}"/&gt;
  233. &lt;/classpath&gt;
  234. </pre>
  235. <hr>
  236. <p align="center">Copyright &copy; 2002-2004 The Apache Software Foundation. All rights
  237. Reserved.</p>
  238. </body>
  239. </html>