2014-07-08 62 views
2

我正在閱讀actionscript中的xml文件。通過複雜的xml節點循環actionscript

我需要遍歷一個名爲「項」爲顯示在下面的圖像的每個節點: -

誰能幫助我?

enter image description here

我想下面的代碼。但它不工作: -

var categoryList:XMLList = [email protected]; 

       for each(var category:XML in categoryList) 
       { 
        trace([email protected]); 

        for each(var item:XML in category.item) 
        { 
         trace(" "[email protected] +": "+ item); 
        } 
       } 

「入口」節點也有一些內部節點,我也想讀這些節點。

致謝categoryList

回答

4

此XML使用命名空間http://www.w3.org/2005/Atom,所以你要考慮的是:

var n:Namespace = new Namespace("http://www.w3.org/2005/Atom"); 
var categoryList:XMLList = x.n::entry; 

更新: 爲了訪問子節點,您將需要繼續使用的命名空間

for each(var category:XML in categoryList) 
{ 
    // this traces the name of the author 
    trace(category.n::author.n::name.toString()); 
} 
+0

感謝Marcela :-),現在categoryList已經值。但是我怎樣才能獲得入口節點的內部值。再次感謝您的努力:-) – AnandMeena

+0

我已更新我的示例,以包括抓住作者的名字,但是我無法在提供的XML中找到任何名爲'item'的元素,所以我不確定你在嘗試什麼在上面的代碼示例中訪問。 – Marcela

1

更改聲明:

var categoryList:XMLList = x.entry; 

它應該遍歷entry節點現在。

+0

謝謝彼得回答,我嘗試過,但它不工作。 – AnandMeena

+0

任何錯誤信息? –

+0

不,它不進入內部循環,categoryList是空的。 – AnandMeena

2

更好的是:

var n:Namespace = new Namespace("http://www.w3.org/2005/Atom"); 
default xml namespace = n; 
var categoryList:XMLList = x.entry;//no namespace type access 
//etc 
default xml namespace = null;