读取XML

TreeMenus.xml
<? xml version="1.0" encoding="utf-8"  ?>
< menus >
    
< node  label ="Mail" >
        
< node  label ="Inbox"   />
        
< node  label ="Personal Folder" >
            
< node  label ="Demo"   />
            
< node  label ="Personal"   />
            
< node  label ="Saved Mail"   />
            
< node  label ="bar"   />
        
</ node >
        
< node  label ="Calendar"   />
        
< node  label ="Sent"   />
        
< node  label ="Trash"   />
    
</ node >
</ menus >

ReadXML.mxml
<? xml version="1.0" encoding="utf-8" ?>
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="vertical"  creationComplete ="initApp()" >
    
< mx:Script >
        
<![CDATA[
            import mx.collections.ArrayCollection;            
            import mx.rpc.events.ResultEvent;
            
            public var loader:URLLoader = new URLLoader();
            public var menus:XML = new XML();
            
            public function initApp():void
            {
                var request:URLRequest = new URLRequest("TreeMenus.xml");
                loader.load(request);
                loader.addEventListener(Event.COMPLETE, completeHandle);
            }
            
            public function completeHandle(e:Event):void
            {
                menus = XML(loader.data);
                var results:XMLList = menus.node;
                
                tree.dataProvider = results;
            }
        
]]>
    
</ mx:Script >
    
< mx:Tree  id ="tree"  width ="218"  height ="397"  labelField ="@label" ></ mx:Tree >
    
< mx:Button  label ="Button" />
</ mx:Application >
var request:URLRequest = new URLRequest("TreeMenus.xml");
这里的TreeMenus.xml也可以用一个输出xml格式的asp.net页面代替,aa.aspx?id=2可以这样接受参数。
URLRequest对象也常用与通过URL添加保存删除数据,如:addNews.aspx?title=新闻标题&content=新闻内容。

你可能感兴趣的:(读取xml)