flash/As3.0 | 2006/06/04 20:47

ActionScript 3.0 features a full implementation of ECMAScript for XML (E4X), recently standardized as ECMA-357. E4X offers a natural, fluent set of language constructs for manipulating XML. Unlike traditional XML parsing API’s, E4X makes XML feel like a native data type of the language. E4X streamlines the development of applications that manipulate XML by drastically reducing the amount of code needed. You can learn more about the E4X specification here:

http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-357.pdf


AS3.0 에 새롭게  E4X(ECMAScript for XML) 를 지원한다. E4X 는 XML을 관리하기 위한 모든 언어를 제공한다. 이젠 플래시에서도 제한된 xml 에서 탈피해 좀 더 효율적인 코드작성이 가능하다.

따로 파서를 만들어 쓰고 있지만  워낙 xml 쓰는 방법이 다양해 정형화된 방법을 찾는데 쉽지 않았다.
시간이 되면 AS2.0 방식도 아래와 같은 방법으로 사용해서 파서를 따로 만들어 쓰는것도 좋은 방법인듯 싶다.
AS3.0 에서부터는 xml 노드 구조만 알면 이제부터 아주 쉽게 데이타 파싱이 가능하다.
내장되어있는 파서인 만큼 특별한 코드가 필요없다.
xml 데이타를 통해 노드구조를 접근하면 파서가 알아서 데이타를 추출해 준다. 또한 조건 검색을 통한 데이타 검색도 가능하다.

AS3.0 ..... 암튼 무척 기대된다.

  1. package
  2. {
  3. import flash.display.MovieClip;
  4. import flash.util.trace;
  5. public class E4XExample extends MovieClip
  6. {
  7. public function E4XExample()
  8. {
  9. var employees:XML =
  10. <staff>
  11. <employee id="1" status="active">
  12. <name>Christian Cantrell</name>
  13. <position>CEO</position>
  14. <startDate>12/1/2001</startDate>
  15. </employee>
  16. <employee id="2" status="active">
  17. <name>Danny Dura</name>
  18. <position>Developer</position>
  19. <startDate>4/9/2003</startDate>
  20. </employee>
  21. <employee id="3" status="contractor">
  22. <name>Mike Chambers</name>
  23. <position>Director</position>
  24. <startDate>8/11/1999</startDate>
  25. </employee>
  26. <employee id="4" status="active">
  27. <name>Scott Fegette</name>
  28. <position>President</position>
  29. <startDate>2/4/1889</startDate>
  30. </employee>
  31. </staff>
  32. //All employees\' names (as an XMLList)
  33. trace(employees.employee.name);
  34. // The first employee\'s name
  35. // Christian
  36. trace(employees.employee[0].name);
  37. // All IDs (as an XMLList)
  38. // 1234
  39. // The name of the employee with an ID of 2
  40. // Danny Dura
  41. trace(employees.employee.(@id==2).name);
  42. // The employee with the name "Christian Cantrell"
  43. // Returns an XMLList
  44. trace(employees.employee.(name == "Christian Cantrell"));
  45. // Employee #3\'s start date
  46. // 8/11/1999
  47. trace(employees.employee.(@id==3).startDate);
  48. // All contractors (as XMLList)
  49. trace(employees.employee.(@status=="contractor"));
  50. // All contractors\' names (as XMLList)
  51. trace(employees.employee.(@status=="contractor").name);
  52. // All employees with IDs less than or equal to 2
  53. // Returns an XMLList
  54. trace(employees.employee.(@id <= 2));
  55. // Iterate through all start dates
  56. var item:XML;
  57. for each (item in employees..startDate)
  58. {
  59. trace(item);
  60. }
  61. }
  62. }
  63. }

 
 
태그 : , , ,
이 글의 관련글(트랙백) 주소 :: http://kimkijeung.com/trackback/25

Name 
Password 
Homepage 
  secret
Comment 
  글쓰기


[PREV] [1] ... [80][81][82][83][84][85][86][87][88] ... [105] [NEXT]

 
전체 (105)
flash (74)
math&physics (4)
programming (11)
Flex2 (1)
Mac (2)
photo (0)
project (6)
주저리주저리 (3)
유용한 자료들 (1)
diary (0)
Book (1)
web (2)
«   2009/01   »
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31