Ant xmltask adding a blank xmlns=“”

▼魔方 西西 提交于 2021-02-19 08:41:33

问题


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.


回答1:


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




回答2:


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"/>


来源:https://stackoverflow.com/questions/37946554/ant-xmltask-adding-a-blank-xmlns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!