1

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>
jim
  • 8,670
  • 15
  • 78
  • 149

1 Answers1

1

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>
Patrice M.
  • 4,209
  • 2
  • 27
  • 36