FLEX 合并两个XML的属性
时间:2011-03-10 来源:春哥也编程
例如:
oldXml
<object datePoint="2011-03-05" PT_staticCount="3" UOC_staticCount="3"/> <object datePoint="2011-03-06" PT_staticCount="5" UOC_staticCount="9"/> <object datePoint="2011-03-07" PT_staticCount="9" UOC_staticCount="7"/> <object datePoint="2011-03-08" PT_staticCount="15" UOC_staticCount="9"/> <object datePoint="2011-03-09" PT_staticCount="6" UOC_staticCount="5"/> <object datePoint="2011-03-10" PT_staticCount="6" UOC_staticCount="4"/>
newXml
<object datePoint="2011-03-05" UOC_staticCount="3"/> <object datePoint="2011-03-06" UOC_staticCount="9"/> <object datePoint="2011-03-07" UOC_staticCount="7"/> <object datePoint="2011-03-08" UOC_staticCount="9"/> <object datePoint="2011-03-09" UOC_staticCount="5"/> <object datePoint="2011-03-10" UOC_staticCount="4"/>
可以是用如下函数进行合并
private function mergeTwoXml(oldXml:XMLList, newXml:XMLList, propertyInNewXMl:String):XMLList { for(var i:int = 0; i < oldXml.length(); i++) { oldXml[i].@[propertyInNewXMl+"_staticCount"] = newXml[i].attribute(propertyInNewXMl+"_staticCount"); } return oldXml; }
输出的内容为:
<object datePoint="2011-03-05" PT_staticCount="3" UOC_staticCount="3"/> <object datePoint="2011-03-06" PT_staticCount="5" UOC_staticCount="9"/> <object datePoint="2011-03-07" PT_staticCount="9" UOC_staticCount="7"/> <object datePoint="2011-03-08" PT_staticCount="15" UOC_staticCount="9"/> <object datePoint="2011-03-09" PT_staticCount="6" UOC_staticCount="5"/> <object datePoint="2011-03-10" PT_staticCount="6" UOC_staticCount="4"/>
相关阅读 更多 +