jim
jim

Reputation: 9138

XMLTask to alter this elements text content

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

Answers (1)

Patrice M.
Patrice M.

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

Related Questions