2014-03-25 66 views
1

如何刪除E4X中XML節點上的屬性?我認爲這會更容易,但我還沒有找到任何例子。如何刪除XML中的屬性?

我想:

delete xml.attribute("myAttribute"); 

使我有以下錯誤:

TypeError: Error #1119: Delete operator is not supported with operand of type XMLList. 

,我已經試過:

xml.attribute("myAttribute") = null; 

這會導致編譯錯誤。

回答

2

在你比如剛纔添加的[0]在結果的XMLList,以確保您刪除單個屬性節點,它應該工作:

delete [email protected][0]; 

其實,對我來說deleteXMLList作品以及簡單的情況下(無需複雜E4X搜索結構):

var x:XML = <x><c a="1"/><c a="2"/></x>; 
    trace("0", x.toXMLString()); 
    delete [email protected]; 
    trace("1", x.toXMLString()); 

輸出:

[trace] 0 <x> 
[trace] <c a="1"/> 
[trace] <c a="2"/> 
[trace] </x> 
[trace] 1 <x> 
[trace] <c/> 
[trace] <c/> 
[trace] </x> 
+0

我的屬性位於根節點上。如果你把'a'放在'x'上,你會得到我在OP中提到的錯誤嗎? –

+0

爲根屬性,這對我來說和我的例子一樣,這都很好(我在SDK 3.6A和SDK 4.6上檢查過)。你使用哪個SDK? – fsbmain

+0

我也使用4.6。它現在有效。我與早期版本進行了比較,我曾嘗試過'刪除xml.attribute(「myAttribute」);'但沒有嘗試'刪除xml。@ myAttribute;'就像在你的答案中一樣。謝謝 –