How to replace value of an XML field using Ant?

后端 未结 1 1126
北荒
北荒 2021-01-21 15:36

In an Ant script, I need to replace the value of javax.persistence.jdbc.url property in the following persistence.xml file.



        
相关标签:
1条回答
  • 2021-01-21 16:18

    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>  
    
    0 讨论(0)
提交回复
热议问题