In an Ant script, I need to replace the value of javax.persistence.jdbc.url
property in the following persistence.xml file.
As mentioned by @Rao, your problem is the xpath not dealing properly with namespaces. The syntax that utilizes ":" hasn't worked consistently for me. As many other XmlTask answers have shown on this site, you need to use the //*[local-name()='persistence']
syntax instead.
Also, attribute can be referenced with the @name
syntax.
Last, if you want to replace the value of an attribute, don't use <replace xpath="...
, use <attr xpath="...
Please try:
<xmltask source="${persistence-xml-file-path}" dest="${persistence-xml-file-path}_replaced" report="true">
<attr path="/*[local-name()='persistence']/*[local-name()='persistence-unit']/*[local-name()='properties']/*[local-name()='property'][@name='testprop']" attr="value" value="replaced" />
</xmltask>