Search code examples
antxmltask

xmltask error when replacing node in xml file


I got an error when runnning target replace to xmltask:

C:\Tools\build.xml:432: The following error occurred while executing this line:
C:\Tools\build.xml:408: Failed to specify text in replace

the problem is that my coworker had no issues running the same code on his computer. I can't figure out why I got the error while my coworker didn't.

the part of build.xml is as follow:

<target name="replace" depends="init" description="replace node.">

    <xmltask source="${my-file}" dest="${my-file}"> 

        <replace path=
            "/*[local-name()='server']
              /*[local-name()='profile']
               /*[local-name() = 'subsystem'][1]" 
        withFile="${devlogfile}"/> 

    </xmltask>
</target>

<target name="init">
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${ant.lib.dir}/ant-contrib-1.0b3.jar"/>
        </classpath>
    </taskdef>
    <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
        <classpath>
            <pathelement path="${ant.lib.dir}/xmltask.jar"/>
        </classpath>
    </taskdef>
</target>

the part of property file is as follow:

my-file=c:/old.xml
devlogfile=c:/new.xml

Solution

  • [Converted from the comments section]

    Did you compare the jdk and classpath in the case of your co-worker and yourself ? It's impossible to tell with the information given so far, but it's possible you are using different parsers.

    The error message suggests Ant doesn't find the devlogfile file itself. Are you sure the properties file is passed properly to your ant runtime ? How are you passing it ?