简单的as3操作xml

package  

{

    import flash.display.Sprite;

    import flash.events.Event;

    import flash.net.URLLoader;

    import flash.net.URLRequest;

    /**

     * ...

     * @author henry

     */

    public class XmlTest extends Sprite

    {

        //全局变量

        private var loader:URLLoader=new URLLoader();

        public function XmlTest() 

        {

            init();

        }

        public function init():void 

        {

            trace("henry wang ");

//            var loader:URLLoader = new URLLoader();

            var url:URLRequest = new URLRequest("test.xml");

            loader.addEventListener(Event.COMPLETE, loadHandler);

            loader.load(url);

        }

        public function loadHandler(e:Event):void

        {

            var myXml = new XML(loader.data);

            //trace(myXml.toString());

            trace(myXml.people[0].role+"love" + myXml.people[1].role);

            var SomeXml:XML=

            <people>

                <role>萧筱</role>

                <actor>何莉</actor>

                <profile>模特</profile>

            </people>;

            myXml.appendChild(SomeXml);

            //trace(myXml.toString());

            trace(myXml.people[4].role+"是默笙大学时代的闺蜜");

            trace(myXml.people[3].role.@id);

            trace(myXml.people.(profile == "CEO").role );

            //trace(myXml.child("people").actor);

            var Some1Xml:XML =

            <people>

                 <role>路人甲</role>

                 <actor>群演</actor>

                 <profile>北京电影学院</profile>

            </people>

            myXml.prependChild(Some1Xml);

            trace(myXml.people.length());

        }

    }



}

 处理xml是as3中常用的技术。

你可能感兴趣的:(xml)