Original Post
I'm trying to seperate data stuff from the implementation part and doing so, I've added stuff like different races, classes, spells and such in each of their own XML file. I'm kinda new with XML and I'm having some trouble with reading from the file. Here's a xml example: How could I search up the race which is of type Elf and get to its attributes and elements? How could i loop through all the elements? I've managed to get the value of the first item and its attribute values, but I feel like I'm stumbling in the dark. I've tried searching alot for stuff like "c# read xml attribute" and stuff like that, but the info on the subject is surprisingly sparse. It's probably too obvious. :) I would have thought that using raceItems.Item{1}... would give me the Elf element, but the value seems to have a different meaning.
<?xml version="1.0" encoding="utf-8" ?>
<races>
<race type="Dwarf" size="Medium" baseSpeed="20">
<age minAge="40" middleAge="125" oldAge="188" venerableAge="250" maxAge="2d%" />
<height maleBaseHeight="3.9" femaleBaseHeight="3.7" heightModifier="2d4" />
<weight maleBaseWeight="130" femaleBaseWeight="100" weightModifier="2d6" />
<favoredClass>Fighter</favoredClass>
<abilityStatModifier str="0" dex="0" con="2" int="0" wis="0" cha="-2" />
<knownLanguages>Common</knownLanguages>
<knownLanguages>Dwarven</knownLanguages>
<availableLanguages>Giant</availableLanguages>
<availableLanguages>Gnome</availableLanguages>>
<availableLanguages>Goblin</availableLanguages>
<availableLanguages>Orc</availableLanguages>
<availableLanguages>Terran</availableLanguages>
<availableLanguages>Undercommon</availableLanguages>
<hairColor>Black</hairColor>
<hairColor>Brown</hairColor>
<hairColor>Gray</hairColor>
<hairColor>Charcoal</hairColor>
<hairColor>Raven</hairColor>
<eyeColor>Dark</eyeColor>
<skinColor>Deep Tan</skinColor>
<skinColor>Light Brown</skinColor>
</race>
<race type="Elf" size="Medium" baseSpeed="30">
<age minAge="110" middleAge="175" oldAge="263" venerableAge="350" maxAge="4d%" />
<height maleBaseHeight="4.5" femaleBaseHeight="4.5" heightModifier="2d6" />
<weight maleBaseWeight="85" femaleBaseWeight="80" weightModifier="2d6" />
<favoredClass>Wizard</favoredClass>
<abilityStatModifier str="0" dex="2" con="-2" int="0" wis="0" cha="0" />
<knownLanguages>Common</knownLanguages>
<knownLanguages>Elven</knownLanguages>
<availableLanguages>Gnome</availableLanguages>>
<availableLanguages>Goblin</availableLanguages>
<availableLanguages>Gnoll</availableLanguages>
<availableLanguages>Orc</availableLanguages>
<availableLanguages>Draconiac</availableLanguages>
<availableLanguages>Sylvan</availableLanguages>
<hairColor>Black</hairColor>
<hairColor>Brown</hairColor>
<hairColor>Chestnut</hairColor>
<hairColor>Charcoal</hairColor>
<hairColor>Raven</hairColor>
<hairColor>Chocolate</hairColor>
<hairColor>Cinnamon</hairColor>
<hairColor>Ebony</hairColor>
<hairColor>Mahogany</hairColor>
<hairColor>Blonde</hairColor>
<eyeColor>Green</eyeColor>
<skinColor>Pale</skinColor>
</race>
</races>
System.Xml.XmlNode favoredClass = raceItems.Item(0).SelectSingleNode("race/favoredClass");
Console.Write("Favored class: {0}.\n", favoredClass.InnerText);