ActionScript3.0 中XML与XMLList详解

/****************************************************************************************/
var sXML:XML=new XML();

sXML=<ro>
         <information>
       <name>zhongqi</name>
    <age>58</age>
    <province></province>
   </information>
   <Address>
       <addr id='001'>Beijing</addr>
    <addr id='002'>ShangHai</addr>
    <addr id='003'>Shenzhen</addr>
   </Address>
     </ro>

trace("输出");
trace(sXML.information.age);
trace(sXML.Address.addr[1]);
trace(sXML.Address.addr[2].@id);

输出
58
ShangHai
003

/***************************************************************************************/
创建的方式:
var sXML:XML=new XML();
sXML=<v><c>1</c><s>2</s></v>

var sXML:XML=new XML(<v><c>1</c><s>2</s></v>);

/***************************************************************************************/
调用属性:
var sXML:new XML(
<vegetable>
  <cabbage id='001' price='2.5'>白菜</cabbage>
  <cucumber id='002' price='1.6'>黄瓜</cucumber>
</vegetable>
);
sXML.cabbage.@price
sXML.cucumber.@price

/************************************************************************************/
调用多个相同标签的属性:
var sXML:XML=new XML();
sXML=<ro>
       <vegetable>白菜</vegetable>
       <vegetable>黄瓜</vegetable>
       <vegetable>葱</vegetable>
     </ro>
sXML.vegetable[0]
sXML.vegetable[1]
sXML.vegetable[2]

/****************************************************************************/
将存储变量的值传递到XML对象中去
var sXML:XML=new XML();
var cabbage:String="白菜";
var cucumber:String="黄瓜";
var shallot:String="葱";
var garlic:String="蒜";
sXML=<ro>
    <vegetable>{cabbage}</vegetable>
    <vegetable>{cucumber}</vegetable>
    <vegetable>{shallot}</vegetable>
    <vegetable>{garlic}</vegetable>
    </ro>

输出指定条件的元素值:
var sXML:XML=new XML();
sXML=<ro>
      <pro1 id='001'>
       <vegetable>白菜</vegetable>
       <vegetable>黄瓜</vegetable>
       <vegetable>葱</vegetable>
      </pro1>
      <pro1 id='002'>
       <vegetable>白菜</vegetable>
       <vegetable>黄瓜</vegetable>
       <vegetable>葱</vegetable>
      </pro1>
     </ro>
sXML.pro1.(@id='001').vegetable[0]
/******************************************************************/
appendChild()
var sXML:XML=new XML();

sXML=<information>
       <name>zhongqi</name>
       <age>58</age>
       <province></province>
     </information>
  

sXML.appendChild(<Email>****@***.com</Email>);
结果:
     <information>
       <name>zhongqi</name>
       <age>58</age>
       <province></province>
       <Email>****@***.com</Email>
     </information>

prependChild()
同样的如果prependChild(<Email>****@***.com</Email>);
结果是:
    <information>
       <Email>****@***.com</Email>
       <name>zhongqi</name>
       <age>58</age>
       <province></province>
     </information>

***********************************************************************
child方法:
sXML=<information>
       <name>zhongqi</name>
       <age>58</age>
       <province></province>
     </information>
sXML.child("*");输出带标签,所有信息
sXML.child(0);
SXML.child(1);
sXML.child(2);

**********************************************************************
children()
sXML=<information>
       <name>zhongqi</name>
       <age>58</age>
       <province></province>
     </information>
sXML.children()[0]
sXML.children()[1]
***********************************************************************
insertChildAfter()方法
sXML=<information>
       <name>zhongqi</name>
       <age>58</age>
       <province></province>
     </information>
sXML.insertChildAfter(sXML.Name,<book>sqlbook</book>);
结果是:
sXML=<information>
       <name>zhongqi</name>
       <book>sqlbook</sqlbook>
       <age>58</age>
       <province></province>
     </information>
insertChildBefore()同理

************************************************************************
replace方法:
replace(ob:Object,va:XML):XML
sXML=<information>
       <name>zhongqi</name>
       <age>58</age>
       <province></province>
     </information>
sXML.replace(0,<NAME>002</NAME>);
结果是:

sXML=<information>
       <NAME>zhongqi</NAME>
       <age>58</age>
       <province></province>
     </information>

**********************************************************************
setChildren()
attributes()
attribute()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值