• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RyanAchtenSoma · Oct 12, 2015 at 12:13 AM · xmlkeydictionarygenericnode

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);
     }
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

iTween Paths : Element with the same key already exists in the dictionary 5 Answers

KeyNotFoundException: The given key was not present in the dictionary 1 Answer

Dictionary wont give me value with correct key 1 Answer

C# Auto Generated Key with Variable (Hash, Metadata, etc.) 2 Answers

The Given Key cannot be found in the Dictionary and I have no idea why. Worked perfectly before. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges