aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/manual/Tasks/xmlproperty.html
blob: 293cf24551f76083f2657499c1498c7b836f5c32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
<title>XmlProperty Task</title>
</head>

<body>

<h2><a name="xmlproperty">XmlProperty</a></h2>
<h3>Description</h3>
<p>
Loads property values from a well-formed xml file. There are no other restrictions
than "well-formed". You can choose the layout you want. For example this XML property file:
<pre>
  &lt;root&gt;
    &lt;properties&gt;
      &lt;foo&gt;bar&lt;/foo&gt;
    &lt;/properties&gt;
  &lt;/root&gt;
</pre>
is roughly equivalent to this Java property file:
<pre>
  root.properties.foo = bar
</pre>

<p>
By default, this load
does <em>no</em> processing of the input.  In particular, unlike the
<a href="property.html">Property task</a>, property references
(i.e., <samp>${foo}</samp>) are not resolved.
<p>
<a name="semanticAttributes">
<h3>Semantic Attributes</h3>
</a>
Input processing can be enabled by using the <b>semanticAttributes</b>
attribute.  If this attribute is set to <i>true</i> (its default is
<i>false</i>), the following processing occurs as the input XML file
is loaded:
<ul>
  <li>Property references are resolved.</li>
  <li>The following attributes are treated differently:
    <ul>
      <li><b>id</b>: The property is associated with the given id value.</li>
      <li><b>location</b>: The property is treated as a file location</li>
      <li><b>refid</b>: The property is set to the value of the
          referenced property.</li>
      <li><b>value</b>: The property is set to the value indicated.</li>
    </ul>
  </li>
  <li><a href="../using.html#path">Path-like Structures</a> can be defined
      by use of the following attributes:
    <ul>
      <li><b>pathid</b>: The given id is used to identify a path.  The
          nested XML tag name is ignored.  Child elements can be used
          (XML tag names are ignored) to identify elements of the path.</li>
    </ul>
  </li>
</ul>
<p>
For example, with semantic attribute processing enabled, this XML property
file:
<pre>
  &lt;root&gt;
    &lt;properties&gt;
      &lt;foo location="bar"/&gt;
      &lt;quux&gt;${root.properties.foo}&lt;/quux&gt;
    &lt;/properties&gt;
  &lt;/root&gt;
</pre>
is roughly equivalent to the following fragments in a build.xml file:
<pre>
  &lt;property name="root.properties.foo" location="bar"/&gt;
  &lt;property name="root.properties.quux" value="${root.properties.foo}"/&gt;
</pre>

</p>

<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
  <tr>
    <td valign="top"><b>Attribute</b></td>
    <td valign="top"><b>Description</b></td>
    <td align="center" valign="top"><b>Required</b></td>
  </tr>
  <tr>
    <td valign="top">file</td>
    <td valign="top">The XML file to parse.</td>
    <td valign="top" align="center">Yes, or a nested resource collection.</td>
  </tr>
  <tr>
    <td valign="top">prefix</td>
    <td valign="top">The prefix to prepend to each property</td>
    <td valign="top" align="center">No</td>
  </tr>
  <tr>
    <td valign="top">keepRoot</td>
    <td valign="top">Keep the xml root tag as the
                     first value in the property name.</td>
    <td valign="top" align="center">No, default is <i>true</i>.</td>
  </tr>
  <tr>
    <td valign="top">validate</td>
    <td valign="top">Validate the input file (e.g. by a DTD). Otherwise the XML must only be well-formed.</td>
    <td valign="top" align="center">No, default is <i>false</i>.</td>
  </tr>
  <tr>
    <td valign="top">collapseAttributes</td>
    <td valign="top">Treat attributes as nested elements.</td>
    <td valign="top" align="center">No, default is <i>false</i>.</td>
  </tr>
  <tr>
    <td valign="top">semanticAttributes</td>
    <td valign="top">Enable special handling of certain attribute names.
                     See the <a href="#semanticAttributes">Semantic Attributes</a>
                     section for more information.</td>
    <td valign="top" align="center">No, default is <i>false</i>.</td>
  </tr>
  <tr>
    <td valign="top">includeSemanticAttribute</td>
    <td valign="top">Include the semantic attribute name
                     as part of the property name.  Ignored if
                     <i>semanticAttributes</i> is not set to <i>true</i>.
                     See the <a href="#semanticAttributes">Semantic Attributes</a>
                     section for more information.</td>
    <td valign="top" align="center">No, default is <i>false</i>.</td>
  </tr>
  <tr>
    <td valign="top">rootDirectory</td>
    <td valign="top">The directory to use for resolving file references. Ignored
                     if <i>semanticAttributes</i> is not set to <i>true</i>.</td>
    <td valign="top" align="center">No, default is <i>${basedir}</i>.</td>
  </tr>
  <tr>
    <td valign="top">delimiter</td>
    <td valign="top">Delimiter for splitting multiple values.<br><i>since Apache Ant 1.7.1</i></td>
    <td valign="top" align="center">No, defaults to comma</td>
  </tr>
</table>

<h3><a name="nested">Nested Elements</a></h3>
<h4>xmlcatalog</h4>
<p>The <a href="../Types/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a>
element is used to perform entity resolution.</p>

<h4>any <a href="../Types/resources.html">resource</a> or single element
resource collection</h4>

<p>The specified resource will be used as input.</p>

<a name="examples">
<h3>Examples</h3>
</a>

<h4>Non-semantic Attributes</h4>

<p>Here is an example xml file that does not have any semantic attributes.</p>

<pre>
   &lt;root-tag myattr="true"&gt;
    &lt;inner-tag someattr="val"&gt;Text&lt;/inner-tag&gt;
    &lt;a2&gt;&lt;a3&gt;&lt;a4&gt;false&lt;/a4&gt;&lt;/a3&gt;&lt;/a2&gt;
   &lt;/root-tag&gt;
</pre>

<h5>default loading</h5>
<p>This entry in a build file:
<pre>   &lt;xmlproperty file="somefile.xml"/&gt;</pre>
is equivalent to the following properties:
<pre>
   root-tag(myattr)=true
   root-tag.inner-tag=Text
   root-tag.inner-tag(someattr)=val
   root-tag.a2.a3.a4=false
</pre>

<h5>collapseAttributes=false</h5>
<p>This entry in a build file:
<pre>   &lt;xmlproperty file="somefile.xml" collapseAttributes="true"/&gt;</pre>
is equivalent to the following properties:
<pre>
   root-tag.myattr=true
   root-tag.inner-tag=Text
   root-tag.inner-tag.someatt=val
   root-tag.a2.a3.a4=false
</pre>

<h5>keepRoot=false</h5>
<p>This entry in a build file:
<pre>   &lt;xmlproperty file="somefile.xml" keepRoot="false"/&gt;</pre>
is equivalent to the following properties:
<pre>
   inner-tag=Text
   inner-tag(someattr)=val
   a2.a3.a4=false
</pre>

<h4>Semantic Attributes</h4>

<p>Here is an example xml file that has semantic attributes.</p>
<pre>
  &lt;root-tag&gt;
    &lt;version value="0.0.1"/&gt;
    &lt;build folder="build"&gt;
      &lt;classes id="build.classes" location="${build.folder}/classes"/&gt;
      &lt;reference refid="build.classes"/&gt;
    &lt;/build&gt;
    &lt;compile&gt;
      &lt;classpath pathid="compile.classpath"&gt;
        &lt;pathelement location="${build.classes}"/&gt;
      &lt;/classpath&gt;
    &lt;/compile&gt;
    &lt;run-time&gt;
      &lt;jars&gt;*.jar&lt;/jars&gt;
      &lt;classpath pathid="run-time.classpath"&gt;
        &lt;path refid="compile.classpath"/&gt;
        &lt;pathelement path="${run-time.jars}"/&gt;
      &lt;/classpath&gt;
    &lt;/run-time&gt;
  &lt;/root-tag&gt;
</pre>

<h5>default loading (semanticAttributes=true)</h5>
<p>This entry in a build file:
<pre>   &lt;xmlproperty file="somefile.xml" keepRoot="false"
                semanticAttributes="true"/&gt;</pre>
is equivalent to the following entries in a build file:
<pre>
  &lt;property name="version" value="0.0.1"/&gt;
  &lt;property name="build.folder" value="build"/&gt;
  &lt;property name="build.classes" location="${build.folder}/classes" id="build.classes"/&gt;
  &lt;property name="build.reference" refid="build.classes"/&gt;

  &lt;property name="run-time.jars" value="*.jar"/&gt;

  &lt;path id="compile.classpath"&gt;
    &lt;pathelement location="${build.classes}"/&gt;
  &lt;/path&gt;

  &lt;path id="run-time.classpath"&gt;
    &lt;path refid="compile.classpath"/&gt;
    &lt;pathelement path="${run-time.jars}"/&gt;
  &lt;/path&gt;
</pre>

<h5>includeSemanticAttribute="true"</h5>
<p>This entry in a build file:
<pre>   &lt;xmlproperty file="somefile.xml"
                semanticAttributes="true" keepRoot="false"
                includeSemanticAttribute="true"/&gt;
</pre>
is equivalent to the following entries in a build file:
<pre>
  &lt;property name="version.value" value="0.0.1"/&gt;
  &lt;property name="build.folder" value="build"/&gt;
  &lt;property name="build.classes.location" location="${build.folder}/classes"/&gt;
  &lt;property name="build.reference.refid" refid="build.classes"/&gt;

  &lt;property name="run-time.jars" value="*.jar"/&gt;

  &lt;path id="compile.classpath"&gt;
    &lt;pathelement location="${build.classes}"/&gt;
  &lt;/path&gt;

  &lt;path id="run-time.classpath"&gt;
    &lt;path refid="compile.classpath"/&gt;
    &lt;pathelement path="${run-time.jars}"/&gt;
  &lt;/path&gt;
</pre>



</body>
</html>