antwildfly-8xmltask

Using Ant xmltask to add a Datasource to the standalone.xml of wildfly 8


I am exploring the ways automate the installation process of a software using Ant Tool.

Most of which I have been able to accomplish except for one that is editing the wildfly standalone.xml file to add a datasource to it.

I feel the issue here is that the ant xmltask is unable to resolve the multiple namespaces.

I have specified the copy path as <insert path="/:server/:profile/:subsystem[3]/:datasources" unless="modelexists"> , ':' specifying that there is a namespace.

Although it works fine when the namespace is on the server element of standalone but since I am trying to edit the <profile><subsystem> and because the subsystem again has another namespace, it makes it impossible to insert the datasource to it.

I'm hoping somebody can help me out here.

Thanks.


Solution

  • As mentioned on other answers (e.g. How to replace value of an XML field using Ant? ), your problem is Ant not dealing properly with namespaces within xpath. The syntax that utilizes ":" hasn't worked consistently for me. You need to use the //*[local-name()='server'] syntax instead.

    Please try:

    <xmltask source="standalone.xml" dest="standalone.xml" report="true">
       <insert path="*[local-name()='server']/*[local-name()='profile']/*[local-name()='subsystem'][3]/*[local-name()='datasources'] unless="modelexists">       
    </xmltask>