as3中對xml的建立,增加,刪除,修改,檢索
阿新 • • 發佈:2019-01-07
//建立xml物件的兩種方式
var shuju:String="<a><b>你好</b><c>中國</c></a>";
//var xml:XML=new XML(shuju);var xml:XML=
<a>
<b>你好</b>
<b hui="hui">你好2</b>
<c ri="wurihui">中國</c>
<m>
<b hui="new hui">你好3</b>
</m>
</a>
;
//對xml中的元素值進行修改
xml.b[0]="吳日輝";
trace(xml.b[0]);
trace(xml.b[1]);
//訪問xml中的屬性
trace(
//在c標籤下建立子元素
xml.c.e=new XML();
//建立子元素d
xml.d=new XML();
//給子元素d賦值
xml.d="我是新建立的";
//給子元素d新增屬性url
[email protected]="http://www.csdn.net";
//刪除子元素
delete xml.b[0];
//刪除子元素屬性
delete [email protected];
trace(xml);
//檢索子元素
trace(xml..b);
//檢索子元素屬性
trace([email protected]);
//檢索子元素所有屬性
trace(
//按給定條件搜尋,只能檢索到同級的
trace(xml..b.(@hui=="hui"));//等效於trace(xml.b.(@hui=="hui"));