Game Development Reference
In-Depth Information
node = node["Table"];
// Navigate to the first row, which has the column headers
node = node["Row"];
int index = 0;
foreach (XmlNode child in node.ChildNodes)
{
if (child.Name == "Cell")
{
fields[child["Data"].InnerText] = index;
Listing 12.2. C# code to parse the header fields (parsexml.cs).
Next, we need to iterate over each additional row and create objects for each.
The following class and enumerations, shown in Listing 12.3, will be used to store
our data during parsing.
enum CharacterClass
{
Standard,
Armored
}
class CharacterData
{
public string character;
public string description;
public float hitPoints;
public float moveSpeed;
public float attackPower;
public CharacterClass characterClass;
public string thumbnail;
public override string ToString ()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0} ({1})\n", character,
characterClass.ToString());
sb.Append( ￿ \t ￿ );
sb.AppendLine(description);
sb.AppendFormat("\thp: {0:0}\tms: {1:0}\tap: {2:0}\n", hitPoints,
moveSpeed, attackPower);
sb.AppendFormat("\tthumbnail: {0}\n", thumbnail);
return sb.ToString();
Listing 12.3. C# class and enumeration (parsexml.cs).
Search WWH ::




Custom Search