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

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