flex 获取xml节点名称
xml内容如下
<Table1>
<MenuID>SelectAllMenu</MenuID>
<MenuName>SelectAllMenu</MenuName>
<ParentMenuID>菜单查询</ParentMenuID>
<ProcedureID>SelectAllMenu</ProcedureID>
<Note>SelectAllMenu</Note>
</Table1>
我想获取<Table1>节点下所有子节点的名称,就是取出MenuID,MenuName,ParentMenuID,ProcedureID,Note
(只是要取节点名称,而不是节点内容)
[解决办法]
这里有点用到反射的原理,你需要取到xml对象里的table1对象。然后代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
xmlns:Lnkg="jp.co.tac.jnl.ui.common.*">
<mx:Script>
<![CDATA[
import mx.utils.ObjectUtil;
import mx.controls.Alert;
public function buttonClick():void{
var obj:Object = (model.language.dataProvider as Array)[0];
var classinfo:Object=ObjectUtil.getClassInfo(obj);
var i:int = 0;
var array:Array = new Array();
for each (var p:* in classinfo.properties){
if(String(p)){
array[i] = String(p);
i++;
}
}
Alert.show(array[0]+"---------"+array[1]);
}
]]>
</mx:Script>
<mx:Model id="model" source="login.config" />
<mx:HBox width="100%" height="25" horizontalGap="0">
<mx:Button label="click" id="but" click="buttonClick()"/>
</mx:HBox>
<mx:DataGrid x="56" y="250" width="950" dataProvider="{model.language.dataProvider}"/>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<bean>
<language>
<dataProvider>
<key>18</key>
<shortName>JAPANESE</shortName>
</dataProvider>
<dataProvider>
<key>09</key>
<shortName>ENGLISH</shortName>
</dataProvider>
</language>
</bean>