0

xmlタスクがリスト内の要素ごとに1つのノードの値を別のノードにコピーすることは可能ですか?

ソース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="/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>

リスト内のすべての要素について、あるノードから次のノードに値をコピーする方法について何か考えはありますか?

4

1 に答える 1

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.*" />
于 2012-01-13T16:19:21.093 に答える