XML 객체 어셈블 및 변환Flash Player 9 이상, Adobe AIR 1.0 이상 XML 객체 속성 목록의 맨 앞이나 끝에 속성을 추가하려면 다음 예제와 같이 prependChild() 메서드 또는 appendChild() 메서드를 사용합니다. var x1:XML = <p>Line 1</p>
var x2:XML = <p>Line 2</p>
var x:XML = <body></body>
x = x.appendChild(x1);
x = x.appendChild(x2);
x = x.prependChild(<p>Line 0</p>);
// x == <body><p>Line 0</p><p>Line 1</p><p>Line 2</p></body>
지정된 속성의 앞이나 뒤에 속성을 추가하려면 다음과 같이 insertChildBefore() 메서드 또는 insertChildAfter() 메서드를 사용합니다. var x:XML =
<body>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
</body>
var newNode:XML = <p>Paragraph 1.5</p>
x = x.insertChildAfter(x.p[0], newNode)
x = x.insertChildBefore(x.p[2], <p>Paragraph 1.75</p>)
다음 예제와 같이 XML 객체를 구성할 때 중괄호 연산자({ 및 })를 사용하여 다른 변수의 데이터를 참조로 전달할 수도 있습니다. var ids:Array = [121, 122, 123];
var names:Array = [["Murphy","Pat"], ["Thibaut","Jean"], ["Smith","Vijay"]]
var x:XML = new XML("<employeeList></employeeList>");
for (var i:int = 0; i < 3; i++)
{
var newnode:XML = new XML();
newnode =
<employee id={ids[i]}>
<last>{names[i][0]}</last>
<first>{names[i][1]}</first>
</employee>;
x = x.appendChild(newnode)
}
다음과 같이 = 연산자를 사용하여 속성 및 특성을 XML 객체에 지정할 수 있습니다. var x:XML =
<employee>
<lastname>Smith</lastname>
</employee>
x.firstname = "Jean";
x.@id = "239";
이렇게 하면 XML 객체 x가 다음과 같이 설정됩니다. <employee id="239">
<lastname>Smith</lastname>
<firstname>Jean</firstname>
</employee>
+ 및 += 연산자를 사용하면 XMLList 객체를 연결할 수 있습니다. var x1:XML = <a>test1</a> var x2:XML = <b>test2</b> var xList:XMLList = x1 + x2; xList += <c>test3</c> 이렇게 하면 XMLList 객체 xList가 다음과 같이 설정됩니다. <a>test1</a> <b>test2</b> <c>test3</c> |
|