Help using XML as Dictionary key
I'm not quite understanding the key in Dictionaries. I thought if the same key was passed twice it would still only create one pair in the dictionary. Can anyone explain this to me?
With a key of a string or number it seems to work as I would expect, but the XML as key doesn't seem to work. The line in there that changes the title was just to check if the XML was being passed as a reference or value. It is a reference. So it seems like the dictionary should know the key is the same. Why doesn't it?
I'm trying to create an index of the content in some XML Nodes and want to be sure that various nodes don't get added to the index more than once. I also My thinking was to use the XML node itself as as the key. It is the only thing I have in the data that is for sure unique. Is there a way to do what I want to do?
var xmlData:XML=<data>
<session>
<title>Document 1</title>
<desc> <![CDATA[blah blah blah]]></desc>
</session>
<session>
<title>Document 2</title>
<desc> <![CDATA[blah blah blah]]></desc>
</session>
</data>;
var d:Dictionary=new Dictionary();
var xml1:XML=xmlData.session[0];
var xml2:XML=xmlData.session[0];
addToDictionary(xml1);
addToDictionary(xml2);
xmlData.session[0].title="New title";
for(var a:* in d){
trace(a.title+": "+d);
}
function addToDictionary(xml:XML){
d[xml]=int(Math.random()*500);
}
traces
New title: 2
New title: 135