[AS3]as3的解析xml详细源代码
先建立一个类文件,然后拷贝下面代码张贴进类文件中,注意类文件的名字,再建立一个fla文件,捆绑刚才的类
先建立一个类文件,然后拷贝下面代码张贴进类文件中,注意类文件的名字.
再建立一个fla文件,捆绑刚才的类.然后编译下看看 ^_^
- package {
- import flash.display.Sprite;
- public class XmlExample extends Sprite {
- public function XmlExample() {
- var employees:XML =
- <employees>
- <employee ssn="123-123-1234">
- <name first="John" last="Doe"/>
- <address>
- <street>11 Main St.</street>
- <city>San Francisco</city>
- <state>CA</state>
- <zip>98765</zip>
- </address>
- </employee>
- <employee ssn="789-789-7890">
- <name first="Mary" last="Roe"/>
- <address>
- <street>99 Broad St.</street>
- <city>Newton</city>
- <state>MA</state>
- <zip>01234</zip>
- </address>
- </employee>
- </employees>;
- trace(employees.employee[0].address.zip); // 98765
- trace(employees.employee[1].@ssn); // 789-789-7890
- trace(employees.employee.name); // <name first="John" last="Doe"/>
- // <name first="Mary" last="Roe"/>
- trace(employees..zip[0]); // 98765
- trace(employees..@ssn[1]); // 789-789-7890
- trace(employees..name); // <name first="John" last="Doe"/>
- // <name first="Mary" last="Roe"/>
- trace(employees.employee[0].address.*); // <street>11 Main St.</street>
- // <city>San Francisco</city>
- // <state>CA</state>
- // <zip>98765</zip>
- var node:String = "zip";
- trace(employees.employee[0].address[node]); // 98765
- var attribute:String = "ssn";
- trace(employees.employee[1].@[attribute]); // 789-789-7890
- for each (var num:XML in employees..@ssn) {
- trace(num); // 123-123-1234
- } // 789-789-7890
- var ssnToFind:String = "789-789-7890";
- trace(employees.employee.(@ssn == ssnToFind).toXMLString());
- // <employee ssn="789-789-7890">
- // <name first="Mary" last="Roe"/>
- // <address>
- // <street>99 Broad St.</street>
- // <city>Newton</city>
- // <state>MA</state>
- // <zip>01234</zip>
- // </address>
- // </employee>
- trace(employees.employee.( zip==98765).toXMLString());
- //<employee ssn="123-123-1234">
- <name first="John" last="Doe"/>
- <address>
- <street>11 Main St.</street>
- <city>San Francisco</city>
- <state>CA</state>
- <zip>98765</zip>
- </address>
- </employee>
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...