ant xmltask复制文件

时间:2017-05-01 13:40:52

标签: xml ant

我有以下xml文件:

<?xml version="1.0"?>
<job>
<files>
        <file src="file:\C:\tmp\myfile.xml" path="myfile.xml" format="dita"/>
        <file src="file:\C:\tmp\myfile2.xml" path="myfile2.xml" format="dita"/>
</files>
</job>

我尝试使用ant脚本来读取xml文件的内容,然后想要复制相应的文件。这是我的蚂蚁脚本:

<?xml version="1.0" encoding="UTF-8"?>

<project name="TPreProcess" default="start" basedir="." >
<target name="start">
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>

<xmltask source="${basedir}${file.separator}.job.xml" report="false" >  

    <call path="//job/files/file[@format='dita' or @format='ditamap' ]" target="copy-xml"  buffer="abc">
            <param name="copySourcesFile" path="@src"/>
     </call>

</xmltask>
</target>


<target name="copy-xml" depends="" unless="" description="copy xml files">
<copy file="${copySourcesFile}" todir="C:${file.separator}tmp${file.separator}test_dita${file.separator}" failonerror="false" flatten="true"/>
</target>
</project>

ant脚本位于插件文件夹中。在执行的ant文件的日志文件中,始终显示无法找到要复制的文件。你可以看到他总是把插件文件夹放在它之前。

复制的xml:

[copy]警告:找不到文件Q:\ DITA \ Dita-Open-Toolkit \ plugins \ com.xxxxx.dita.tran.process \ file:\ C:\ tmp \ myfile.txt要复制。< / p>

我做错了什么?如何仅获取实际文件路径并找到要复制的文件?

1 个答案:

答案 0 :(得分:0)

我让它像这样运行:

<xmltask source="${basedir}${file.separator}.job.xml" report="false">

<call path="//job/files/file[@format='dita' or @format='ditamap' ]" target="copy-xml"  buffer="abc"> 
<param name="copySourcesFile" path="@src"/> 

</call>


<target name="copy-xml" depends="" unless="" description="copy xml files" >  

 <property name="copySourcesFile" value="${copySourcesFile}" /> 

 <basename property="file.basename" file="${copySourcesFile}"/>
 <dirname property="path.dirname" file="${copySourcesFile}"/>

 <pathconvert property="file.path.stripped">
        <file file="${path.dirname}" />
        <!-- path convert strips off the leading ${basedir} and "\file\:" -->
        <map from="${basedir}\file:\" to="" />
 </pathconvert>  
<copy todir="C:${file.separator}tmp${file.separator}" failonerror="false">
<fileset dir="${file.path.stripped}">
<include name="${file.basename}" />
</fileset>
</copy>
</target>

但我不确定这是不是很好。对此有何评论?怎么会更好?

相关问题