XML.toString bug?

by jozefchutka
♥0 | Line 25 | Modified 2011-06-23 18:47:08 | MIT License
play

ActionScript3 source code

/**
 * Copyright jozefchutka ( http://wonderfl.net/user/jozefchutka )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zcKA
 */

/* XML.toString bug? 
If a xml node contains multiple namespace definitions for the same uri, the XML.toString method is "smart" enough to manipulate the prefix from child nodes. 
This is a dangerous situation while child can have default namespace defined on itself, what in result, moves child node into its default namespace.

item in XML is within xmlns "one"
item in XML.toString() is moved to xmlns "two"

Any idea how to make XML to keep the namespaces correctly?
*/

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.text.TextField;

    [SWF(width="465", height="465", frameRate="30", backgroundColor="#FFFFFF")]
    public class WonderflApp extends Sprite
    {
        public function WonderflApp():void
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            
            var xml:XML = <data xmlns="one" xmlns:one="one">
                <one:item xmlns="two" />
            </data>;
            
            var tf:TextField = new TextField();
            tf.width = stage.stageWidth;
            tf.height = stage.stageHeight;
            tf.text = xml.toString();
            tf.multiline = true;
            addChild(tf);
        }
    }
}