2017-05-01 220 views
0

我有以下XML文件:蚂蚁xmltask文件拷贝

<?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文件的日志文件中,始终显示它无法找到要复制的文件。你可以看到他总是把插件文件夹放在它之前。


复制XML:

[副本]警告:找不到文件Q:\ DITA \蒂塔 - 开 - 工具包\插件\ com.xxxxx.dita.tran.process \文件:\ C:\ tmp \ myfile.txt复制。


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

+0

'copy'任务可以复制文件。为什么选择xmltask? – Rao

+0

我试图使用xmltask,因为我必须读取要从xml文件(包括过滤器到某些属性)复制的文件。有文件节点的属性值不应复制。或者我可以不使用xmltask来读取xml文件?一个主意? – Apollo102

+0

复制始终根据之前的basedir条目构建路径。当我将basedir条目更改为“。”以外的内容时,它不再需要以前的插件文件夹。通过目标中的copySourcesFile的测试输出,我可以看到要正确复制的实际文件名到达目标中。因此,副本本身发生了一些事情但我不知道如何防止这种情况。任何想法? – Apollo102

回答

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> 

但我不知道这是一个很好的sulution。对此有何评论?它会更好吗?