【AS3代码】添加/删除XML子元素及属性
package
{
import flash.display.Sprite;
import flash.xml.XMLDocument;
public class Main extends Sprite
{
private var xl:XML;
public function Main():void
{
xl = new XML(
"<root>" +
"<user name='王翔'>a1内容</user>" +
"<user name='陈璨'>a2内容</user>" +
"<user name='陈武军'>a3内容</user>" +
"</root>"
);
//添加新的子元素、属性/属性的值、子元素的值
xl.c = new XML();
xl.c.@url = "http://www.baidu.com";
xl.c = "C的值!";
//动态删除子元素、子元素属性
delete xl.user[0];
delete xl.user.@name[0];
trace(xl);
}
}
}
{
import flash.display.Sprite;
import flash.xml.XMLDocument;
public class Main extends Sprite
{
private var xl:XML;
public function Main():void
{
xl = new XML(
"<root>" +
"<user name='王翔'>a1内容</user>" +
"<user name='陈璨'>a2内容</user>" +
"<user name='陈武军'>a3内容</user>" +
"</root>"
);
//添加新的子元素、属性/属性的值、子元素的值
xl.c = new XML();
xl.c.@url = "http://www.baidu.com";
xl.c = "C的值!";
//动态删除子元素、子元素属性
delete xl.user[0];
delete xl.user.@name[0];
trace(xl);
}
}
}