2012-01-11 2 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> 

내 개미 작업에서 위를 달성하기 위해 노력하고있어,하지만 난 con't을 할 수있는 방법을 찾을 수가 여기까지 내가 지금하고있는 일이있다.

<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> 

모든 elemen의 값을 한 노드에서 다른 노드로 복사하는 방법에 대한 아이디어 목록에있는 TS?

+0

는 destination.xml이 예에서는 처음에 비어 있습니까? –

+0

@Brian 그것은'...''a 노드의 내용을 source.xml의 경로로 바꾸려고합니다. – Andrew

답변

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.*" />