Flex: adding an element to a linked XML

GuyA1947

New Member
Take the following code, we have 2 XMLs, the first contains some data that we will link to the second. After doing that, if I want to add an element to the first XML, it gets added to the second XML, and only the second XML.\[code\]<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="init()"> <fx:Script> <![CDATA[ private function init():void { var xml1:XML = <xml1> <data> <element id="1"/> </data> </xml1>; var xml2:XML = <xml2> <data/> </xml2>; trace("xml1:"); trace(xml1); trace("xml2:"); trace(xml2); trace("-------------"); xml2.data.appendChild(xml1.data.children()); trace("xml1:"); trace(xml1); trace("xml2:"); trace(xml2); trace("-------------"); xml1.data.appendChild(<element id="2"/>); trace("xml1:"); trace(xml1); trace("xml2:"); trace(xml2); } ]]> </fx:Script></s:Application>\[/code\]The expected outcome would be:\[code\]xml1:<xml1> <data> <element id="1"/> <element id="2"/> </data></xml1>xml2:<xml2> <data> <element id="1"/> </data></xml2>\[/code\]Or perhaps:\[code\]xml1:<xml1> <data> <element id="1"/> <element id="2"/> </data></xml1>xml2:<xml2> <data> <element id="1"/> <element id="2"/> </data></xml2>\[/code\]But the outcome here is:\[code\]xml1:<xml1> <data> <element id="1"/> </data></xml1>xml2:<xml2> <data> <element id="1"/> <element id="2"/> </data></xml2>\[/code\]Why is that?
 
Back
Top