source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/docs/manual/CoreTasks/xmlproperty.html@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

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