加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex 复杂XML 解析XML

发布时间:2020-12-15 03:44:38 所属栏目:百科 来源:网络整理
导读:root ? row ID="50300;123" 编号="shebei" 备用5="" 备用6="" / ? row ID="455;50300" 编号="shebei" 备用5="" 备用6="" / /root 把ID分割成 ID='50300'和ID='123' fx:Declarations ??fx:XML source="test/input.xml" id="input"/ ?/fx:Declarations 解析成

<root>
? <row ID="50300;123" 编号="shebei" 备用5="" 备用6="" />
? <row ID="455;50300" 编号="shebei" 备用5="" 备用6="" />
</root>

把ID分割成 ID='50300'和ID='123'

<fx:Declarations>
??<fx:XML source="test/input.xml" id="input"/>
?</fx:Declarations>

解析成:

<root>

<node label="名称">

?? <node1 id='123'>
????????? <row ID="50300;123" 编号="shebei" 备用5="" 备用6="" />
??????? <row ID="455;50300" 编号="shebei" 备用5="" 备用6="" />

?? <node1>

<node/>

</root>

解析结果如下面:

?var root:XML = <root/>;
????var rowLength :int = input.children().length();
????var rowInfo:String = input.children().@['ID'];
????for(var i:int=0;i<rowLength;i++){
?????var arr:Array = rowInfo.split(";");
?????var row:XML =input.children()[i];
?????for(var j:int=0;j<arr.length;j++){
??????var node2:XML= ObjectUtil.clone(row) as XML;????
??????//?var info:ElemInfo = topoHandle.getElemById(arr[j]);
??????
??????if( topoHandle.getElemById(arr[j]) == null){
???????continue;
??????}
??????var type:String =? topoHandle.getElemById(arr[j]).type;//不需要你们判断
??????var node:XML;
??????if(root.children().(@label == type )==undefined || input.children() ==null){
???????node=<node/>;
???????node.@label =‘名称’;//换成自己的名字
???????root.appendChild(node);
??????}else{
???????node = root.children().(@label =='名称')[0];
??????}
??????var node1:XML;
??????if(node.children() == null || node.children().(@id == arr[j]) == undefined){
???????node1 = <node1/>;
???????node1.@id = arr[j];
???????node.appendChild(node1);
??????}else{
???????node1 = node.children().(@id == arr[j])[0];
??????}
??????node1.appendChild(node2);
?????}
?????
????}
????root.appendChild(node);
????//????trace(root);
????trace(node);

?

?

写的比较烂? 大家只看流程解析就可以 代码不好用 请见谅 提供的是思路

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读