/****************************************************************************************/
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()