- Home /
Storing XML node and accessing from a dictionary
Hi Unity Community
I am trying to store a string and xml node within a generic dictionary and then debug its contents.
It is currently debugging twice, once for each of the relevant nodes (suggesting to me that there are two entries in the dictionary which is perfect) however it is not providing me the contents of these entries (I am trying to catch the name of the node via the Dictionary.Key).
Since this is not throwing any errors I am at a loss as to where I am going wrong, can anyone help me identify the issue here?
Many thanks in advance, Ryan
Edit:
Previously I was accessing the value property incorrectly. This has been resolved, however I am still not able to access the XML node stored as the TValue in the dictionary, leading me to question; are Generic.Dictionaries able to store XML Node as their Value type? Nothing I try is able to resolve this.
Current Code:
function browseXml(browseType : String)
{
xmlRoot = browseInfoCont.browseControl.root;
var mpo = xmlRoot.SelectNodes("MetaPipeObject"); // /ContextualInfo/ContextMedia
var searchResults : boolean = false;
Debug.Log("Search query for: " + browseType);
//***Dictionary test***
var curObjName : String;
var curObjNode : XmlNode;
var browseResults = new Dictionary.<String , XmlNode>();
for (var i = 0; i < mpo.Count; i++){
var curNode = mpo[i];
var createTypeNodeCheck = curNode.SelectNodes("./ModelInfo/ModelCreateType[contains(.,'" + browseType + "')]");
if (createTypeNodeCheck.Count >= 1)
{
searchResults = true;
//***Dictionary test***
curObjName = curNode.SelectSingleNode("@name").Value;
browseResults.Add(curObjName, curObjNode);
//browseImportObj.importObj(curNode);
}
}
if (searchResults == false)
{
Debug.Log("No matches to query");
}
//var kvp = KeyValuePair.<String, XmlNode>(curObjName, curObjNode);
//for(kvp in browseResults)
for(curObjName in browseResults.Keys)
{
//Debug.Log("Dictionary Result: curObjName: " + browseResults.ContainsKey(curObjName)); //true
var curValue : XmlNode = browseResults[curObjName];
var meshLocation : String = curValue.SelectSingleNode("./MeshLocatione").InnerText;
Debug.Log("Dictionary Result: curObjName: " + meshLocation);
}
}