Akshata Shetty
Akshata Shetty

Reputation: 41

Ant xmltask adding a blank xmlns=""

Below is the complete ant target which I am running to insert the driver to my wildfly standalone.xml:

<target name="xmlrewrite" >
    <!--Driver-->
    <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
    <xmltask source="standalone.xml" dest="standalone.xml" report="true">
        <copy path="//driver[@module='com.oracle.ojdbc6']/text()" property="modelexists"/>
        <insert
            path="*[local-name()='server']/*[local-name()='profile']/*[local-name()='subsystem'][3]/*[local-name()='datasources']/*[local-name()='drivers']" 
            unless="modelexists">
            <![CDATA[
                <driver name="oracle" module="com.oracle.ojdbc6">
                <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
                </driver>
            ]]>
        </insert>
    </xmltask>
</target>

As per my understanding, the entry should be made in the standalone.xml only if it is not already present, since i am using unless="modelexists".

But apparently it is making a new entry for oracle driver with an additional xmlns="", which makes two entries of oracle and this causes my build to fail.

Please let me know if you would need any more info.

Upvotes: 4

Views: 938

Answers (2)

SEBiGEM
SEBiGEM

Reputation: 608

To solve the problem with the new entry for oracle driver with an additional xmlns="" you have to provide the namespace (found at the root element in the xml) for the node driver in the CDATA section:

<driver xmlns="namespace_for_this_xml" name="oracle" module="com.oracle.ojdbc6">
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>

Source

Upvotes: 2

Chad Nouis
Chad Nouis

Reputation: 7041

I'm guessing the standalone.xml file is related to JBoss. The XML elements in a JBoss standalone.xml are in XML namespaces. So, the <copy> element nested under <xmltask> will need to be namespace-aware:

<copy path="//*[local-name()='driver' and @module='com.oracle.ojdbc6']/text()" property="modelexists"/>

Upvotes: 0

Related Questions