Reputation: 9138
Considering the following XML, how can I use the Ant task XMLTask
to change bar using foo as a filter if there many items like this with different names.
<string name="foo">bar</string>
<string name="another">a value goes here</string>
<string name="somethingelse">some other value</string>
Upvotes: 1
Views: 204
Reputation: 4319
First of all, we'll assume your xml is actually valid and include a top-level element, e.g.
<mydocument>
<string name="foo">bar</string>
<string name="another">a value goes here</string>
<string name="somethingelse">some other value</string>
</mydocument>
Then, the XPath expression for your specific <string>
elements is:
//string[@name='foo']
(and for the value, add \text()
.
Finally, the XmlTask becomes, for instance:
<xmltask source="source.xml" dest="target.xml">
<replace path="//string[@name='foo']/text()" withText="foobar"/>
</xmltask>
Upvotes: 1