2011-02-14 3 views
0

나는 액션 스크립트 2.0액션 스크립트 2.0 읽기 XML 파일

와 XML 파일을 읽기 위해 노력하고있어 문제가 난 단지 자신의 위치를 ​​참조하여 태그의 값을 읽어 내 코드를 만들 수있다.

태그 이름을 참조하여 XMl 파일에서 값을 검색하는 방법은 무엇입니까?

직접 childNodes 배열에서 이름으로 노드를 검색 할 수 없습니다

AS2에서
<weather> 
    <current> 
     <icon>Partly cloudy</icon> 
     <temphigh>33</temphigh> 
     <templow>24</templow> 
     <humhigh>55</humhigh> 
     <humlow>95</humlow> 
    </current> 
    <forecast1> 
     <day>Monday</day> 
     <icon>rss_ts2</icon> 
     <temphigh>33</temphigh> 
     <templow>24</templow> 
    </forecast1> 
    <forecast2> 
     <day>Tuesday</day> 
     <icon>rss_ts2</icon> 
     <temphigh>32</temphigh> 
     <templow>23</templow> 
    </forecast2> 
    <forecast3> 
     <day>Wednesday</day> 
     <icon>rss_ts2</icon> 
     <temphigh>32</temphigh> 
     <templow>23</templow> 
    </forecast3> 
</weather> 

답변

1

다음 var currentIcon = myXML.firstChild.firstChild.childNodes['icon'].firstChild;

내 XML 파일 인은 (당신은 E4X와 점 표기법으로 AS3에서 할 수 있습니다) . 이 같은 XML2Object 파서를 사용하여 네이티브 AS2 개체에 XML로드 변환해야합니다 :

http://www.sephiroth.it/weblog/archives/2004/01/xml2object.php

그런 다음 당신이 weather.current.icon 같은 점 표기법으로 XML에 액세스합니다.
링크에는 XML2Object AS2 클래스와 몇 가지 예가 포함되어 있습니다.
여러 AS2의 XML-도 있습니다 http://www.thetechlabs.com/tech-tutorials/xml/working-with-xml-e4x-and-actionscript-3/

+1

>의 Obj 파서에 http://proto.layer51.com/ :

이 링크는 XML의 AS2 문서 및 AS3을 처리하는 방법에 대한 차이를 설명 – ocodo