GDF Xml file format

The GDF file is an xml file associated with games in vista.  The file gives information about the various ratings associated with the game along with the name of the game.  The XML file format is fairly simple and is as follows:

 <GameDefinitionFile>
    <GameDefinition>
        <Version>
            <VersionNumber versionNumber="x.y.y.y" />
        </Version>
    <Name>name of game</Name>
    <GameExecutables>
        <GameExecutable path="xyz.exe" />
        ...
    </GameExecutables>
    <Ratings>
        <Rating ratingId='<rating guid>' ratingSystemID='<rating system guid>'>
            <Descriptor descriptorID='<descriptor guid>' />
        </Rating>
        ...
        </Ratings>
    </GameDefintion>
    ...
</GameDefinitionFile>
  

Here is a simple C# class to read in and parse a GDF file. It assumes you are given an xml file as an input.

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Data.SqlClient;
using WpcData;

namespace WpcGames
{
    class GDFFile
    {
        List<GameDefinition> _games;

        public GDFFile(XmlDocument doc)
        {
            _games = new List<GameDefinition>();
            // Lets go through this and do some happy parsing.
            foreach (XmlNode node in doc.ChildNodes)
            {
                if (node.Name == "GameDefinitionFile")
                {
                    ParseGDF(node);
                }
            }
        }

        internal List<GameDefinition> Games
        {
            get { return _games; }
        }

        private void ParseGDF(XmlNode list)
        {
            foreach (XmlNode node in list.ChildNodes)
            {
                if (node.Name == "GameDefinition")
                {
                    Guid gameId = new Guid(node.Attributes["gameID"].Value);
                    //Guid wmid = new Guid(node.Attributes["WMID"].Value);
                    Guid wmid = Guid.Empty;
                    GameDefinition def = new GameDefinition(gameId, wmid);

                    _games.Add(def);

                    ParseGameDefinition(def, node);
                }
            }
        }

        private void ParseGameDefinition(GameDefinition def, XmlNode node)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.Name == "Version")
                {
                    foreach (XmlNode inner in child.ChildNodes)
                    {
                        if (inner.Name == "VersionNumber")
                        {
                            def.Version = inner.Attributes["versionNumber"].Value;
                        }
                    }
                }
                else if (child.Name == "Name")
                {
                    def.Name = child.InnerText;
                }
                else if (child.Name == "Ratings")
                {
                    ParseRatings(def, child);
                }
            }
        }

        private void ParseRatings(GameDefinition def, XmlNode node)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.Name == "Rating")
                {
                    Guid RatingID = new Guid(child.Attributes["ratingID"].Value);
                    //Guid SystemID = new Guid(child.Attributes["ratingSystemID"]);
                    def.Ratings.Add(RatingID);
                    ParseDescriptors(def, child);
                }
            }
        }

        private void ParseDescriptors(GameDefinition def, XmlNode node)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.Name == "Descriptor")
                {
                    Guid DescriptorID = new Guid(child.Attributes["descriptorID"].Value);
                    def.Descriptors.Add(DescriptorID);
                }
            }
        }
    }
}