2010-01-15 7 views
2

XML과 Java의 병합에 대한 여러 게시물이 있지만 동일한 작업에 대한 Actionscript에 대한 참조를 찾을 수없는 것 같습니다.AS3 : XML 파일 병합

로드해야하는 XML 파일 그룹이 있습니다. 나는 그들이 메모리에서 하나의 XML Object로 정렬되기를 원한다.

파일 1

<xml> 
    <type name="1" group="a"> 
     <unit> value1 </unit> 
    </type> 
    <type name="1" group="b"> 
     <unit> value2 </unit> 
    </type> 
    <type name="2" group="a"> 
     <unit> value3 </unit> 
    </type> 
</xml> 

병합 된 2

<xml> 
    <type name="1" group="a"> 
     <unit> value4 </unit> 
    </type> 
    <type name="1" group="b"> 
     <unit> value5 </unit> 
    </type> 
    <type name="2" group="a"> 
     <unit> value6 </unit> 
    </type> 
    <type name="3" group="a"> 
     <unit> value7 </unit> 
    </type> 
</xml> 

파일 : 예를 들어

,의이 내 XML 파일이었다 가정 해 봅시다

<xml> 
    <type name="1" group="a"> 
     <unit> value1 </unit> 
     <unit> value4 </unit> 
    </type> 
    <type name="1" group="b"> 
     <unit> value2 </unit> 
     <unit> value5 </unit> 
    </type> 
    <type name="2" group="a"> 
     <unit> value3 </unit> 
     <unit> value6 </unit> 
    </type> 
    <type name="3" group="a"> 
     <unit> value7 </unit> 
    </type> 
</xml> 

이 예에서는 두 파일이 병합되고 단위는 같은 형식 이름과 그룹 내에 배치됩니다.

정렬 우선 순위 : 유형 이름> 형식 그룹> 단위 값

나는 그것이 분명 바랍니다. 추가 설명이 필요한지 물어보십시오.

답변

2

주어진 예제에서 작동합니다.

var t1:XML, t2:XML; 
var merged:XML = new XML(file1.toXMLString()) 
for each(t1 in merged.type) 
    for each(t2 in file2.type.(@name == [email protected] && @group == [email protected])) 
    t1.appendChild(t2.unit.toXMLString()); 
for each(t2 in file2.type) 
    if(merged.type.(@name == [email protected] && @group == [email protected]).length() == 0) 
    merged.appendChild(t2.toXMLString()); 
trace(merged.toXMLString());