2009-12-22 82 views
1

有一個XML屬性破折號,我不知道如何對其進行過濾: 在這裏你可以看到XML的一個簡單的例子:ActionScript3:過濾包含破折號的xml屬性?

<posts> 
<post> 
    <photo-url max-width="1280">http://blabla.tumblr.com/photo/98</photo-url> 
</post> 
</posts> 

因爲也可在照片的URL標記有一個破折號,我需要解析它...孩子(「照片網址」)。 這工作得很好,但如果我想過濾這些標籤(照片網址),爲了接收所有照片網址的相同屬性:「max-widht ='1280'」,我無法做到這一點。 我嘗試這樣的做法:

var photoUrl:XMLList = xml.posts.post.child("photo-url").(@max-width==1280); 

我得到這個錯誤:

ReferenceError: Error #1065: Variable @max is not defined. 

THX

回答

1

我不認爲你可以直接做到這一點。而不是嘗試使用..每個..在。

var photoUrls:XMLList = xml.posts.post.child("photo-url"); 
for each (var child in photoUrls) { 
    if (child.attribute("max_width") == "1280"); 
    trace(child); 
} 

0

就像你固定的 「照片網址」 與孩子()函數,你也應該使用.attribute(「max-width」)修復max-width屬性。

所以你行應該是這樣的:

var photoUrl:XMLList = xml.posts.post.child("photo-url").(attribute("max-width")==1280);