title: How to replace value of an XML field using Ant?
body: <p>In an Ant script, I need to replace the value of <code>javax.persistence.jdbc.url</code> property in the following persistence.xml file.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
      &lt;persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;class&gt;org.somecompany.domain.SomeEntity&lt;/class&gt;
          &lt;validation-mode&gt;NONE&lt;/validation-mode&gt;
          &lt;properties&gt;
              &lt;property name="testprop" value="testval" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p></p>
  
  <p>I've downloaded XMLTask and have tried the following:</p>
  
  <pre><code>&lt;xmltask source="${persistence-xml-file-path}" dest="${persistence-xml-file-path}_replaced" report="true"&gt;
      &lt;replace path="/:persistence/:persistence-unit/:properties/:property[:name/text()='testprop']/:value/text()" withText="replaced" /&gt;
  &lt;/xmltask&gt;  
  </code></pre>
  
  <p>Unfortunately, this doesn't work. I don't get any errors. Contents of both source and destination xml files appear in console and they're the same. It's as if the replace instruction quoted above never runs (or never identifies the property to update). </p>
  
  <p><strong>=== Following Response from Patrice ===========================================</strong></p>
  
  <p>This seems to work without schema definition for persistence tag:</p>
  
  <pre><code>&lt;xmltask source="${persistence-xml-file-path}" dest="${persistence-xml-file-path}_replaced" report="true" failWithoutMatch="true"&gt;
  &lt;attr path="persistence/persistence-unit/properties/property[@name='testprop']" attr="value" value="replaced"/&gt;
  &lt;/xmltask&gt;
  </code></pre>
  
  <p>This seems to work with schema definition for persistence tag:</p>
  
  <pre><code>&lt;xmltask source="${persistence-xml-file-path}" dest="${persistence-xml-file-path}_replaced" report="true" failWithoutMatch="true"&gt;
  &lt;attr path="//*[@name='testprop']" attr="value" value="replaced"/&gt;
  &lt;/xmltask&gt;
  </code></pre>
  
  <p>Attributes I need to process are very unique, so this is going to work fine for me without the need to examine entire attribute path.</p>