【AS3代码】XML操作
package
{
import flash.display.Sprite;
public class Main extends Sprite
{
public function Main():void
{
init();
}
private function init():void
{
var foo:String =
"<websites>" +
"<site name='Kingda blog' url='http://www.kingda.org'>" +
"<pageview>100000</pageview>" +
"</site>" +
"<site name='ActionScript3' url='http://www.actionscript3.cn'>" +
"<pageview>4500</pageview>" +
"</site>" +
"</websites>";
var kingdaXML:XML = new XML(foo);
kingdaXML.site[0].author = new XML();
//添加空白新节点
kingdaXML.site[0].author = "新节点值";
//添加一个属性
kingdaXML.site[0].author.@uu = "属性值";
//再天津爱一个location节点并赋值
kingdaXML.site[0].location = "AAAAAAAAAAA";
//将新添加的location节点删掉
delete kingdaXML.site[0].location;
trace(kingdaXML);
//查找值小于50000的pageview子元素
trace(kingdaXML.site.(pageview < 50000));
//查找值等于Kingda blog的属性name子元素
trace(kingdaXML.site.(@name == "Kingda blog"));
}
}
}
{
import flash.display.Sprite;
public class Main extends Sprite
{
public function Main():void
{
init();
}
private function init():void
{
var foo:String =
"<websites>" +
"<site name='Kingda blog' url='http://www.kingda.org'>" +
"<pageview>100000</pageview>" +
"</site>" +
"<site name='ActionScript3' url='http://www.actionscript3.cn'>" +
"<pageview>4500</pageview>" +
"</site>" +
"</websites>";
var kingdaXML:XML = new XML(foo);
kingdaXML.site[0].author = new XML();
//添加空白新节点
kingdaXML.site[0].author = "新节点值";
//添加一个属性
kingdaXML.site[0].author.@uu = "属性值";
//再天津爱一个location节点并赋值
kingdaXML.site[0].location = "AAAAAAAAAAA";
//将新添加的location节点删掉
delete kingdaXML.site[0].location;
trace(kingdaXML);
//查找值小于50000的pageview子元素
trace(kingdaXML.site.(pageview < 50000));
//查找值等于Kingda blog的属性name子元素
trace(kingdaXML.site.(@name == "Kingda blog"));
}
}
}