Obtain string representation of XML node

error_040

New Member
\[code\]public void AssignSkillFromXml(string xmlCharID, string skillNodeDir){ XmlDocument doc = new XmlDocument(); doc.Load(@"/home/holland/code/svn/chronos-/trunk/chronos/Lib/XmlFiles/Characters.xml"); XmlNode node = doc.SelectSingleNode("Character/"+xmlCharID+"/Skills/"+skillNodeDir+"/text()"); foreach(KeyValuePair<Skill, int> entry in skills) { bool nodeEqualsKey = (node.Name.ToString() == entry.Key.ToString()); Console.WriteLine(entry.Key); if (nodeEqualsKey) { int val; int.TryParse(node.Value, out val); skills[entry.Key] = val; Console.WriteLine(val); } }}\[/code\]As shown, I have a method which is designed to assign a value from an xml node. The name of the node is supposed to be passed as a string, and accessed through the directory specified by the XmlNode. From there, a foreach loop iterates through a dictionary, comparing the name of the node with the key of the dictionary, which happens to be an enum. The only way this will work is if the enum can be parsed as a string, and compared with the name of the node. I would like to just use the skillNodeDir to compare the skill as such with the enum, but this isn't very safe, and is more subject to human error. Is there an alternative?
 
Top