2012-01-11 50 views
0

对于列表中的每个元素,xml任务是否可以将一个节点的值复制到另一个节点中?使用xmltask将一个值复制到另一个值

源XML:

<a> 
<b> 
    <c1>foo</c1> 
    <c2></c2> 
</b> 
<b> 
    <c1>bar</c1> 
    <c2></c2> 
</b> 
... 
</a> 

目标XML:

<a> 
<b> 
    <c1>foo</c1> 
    <c2>foo</c2> 
</b> 
<b> 
    <c1>bar</c1> 
    <c2>bar</c2> 
</b> 
... 
</a> 

我试图完成上述在我的蚂蚁的任务,但我续似乎找到一个方法来做到这一点,这里是我到目前为止,

<target name="mergefile">  
    <!-- Read the source into a buffer --> 
    <xmltask source="source.xml" clearBuffers="list"> 
     <copy path="/a" buffer="list" append="true"/> 
    </xmltask> 

    <!-- Write them to the output --> 
    <xmltask source="destination.xml" dest="destination.xml" 
     outputter="simple"> 
     <!-- First clear all the old paths. --> 
     <remove path="https://stackoverflow.com/a/b"/> 
    <!-- Then add the resolved ones. --> 
     <paste path="/a" buffer="list"></paste> 
      <!-- Copy the value over? --> 
     <replace path="a/b/c2/text()" withText="No Idea"/> 
    </xmltask> 
</target> 

任何想法如何将值从一个节点复制到下一个所有元素在列表中的ts?

+0

是destination.xml在这个例子中最初是空的? – 2012-01-11 21:07:15

+0

@Brian它有'...'我试图用source.xml中的路径替换'a'节点的内容。 – Andrew 2012-01-11 21:13:06

回答

0

正如我猜想的那样,通常情况下,写我自己的任务是我能看到做到的唯一方法。

@Override 
public void execute() throws BuildException { 
    //Read file line by line, regex test on each line, 
    //matches get written back twice. 
} 

然后调用它,

<copyregmatch file="myfile.xml" regex=".*replace.*" /> 
相关问题