Ejemplo n.º 1
0
        public static Boardgame ParseXml(XmlDocument d)
        {
            if (!d.FirstChild.NextSibling.HasChildNodes) return null;
            var result = new Boardgame();

            //Simple fields
            result.Id = int.Parse(getSimpleValue(d, "/items/item", "id"));
            result.Name = getSimpleValue(d, "/items/item/name[@type='primary']", "value").Replace(';', ':').Replace('\n', ' ').Replace('\r', ' ');
            result.YearPublished = int.Parse(getSimpleValue(d, "/items/item/yearpublished", "value"));
            result.MinPlayers = int.Parse(getSimpleValue(d, "/items/item/minplayers", "value"));
            result.MaxPlayers = int.Parse(getSimpleValue(d, "/items/item/maxplayers", "value"));
            result.PlayingTime = int.Parse(getSimpleValue(d, "/items/item/playingtime", "value"));
            result.MinAge = int.Parse(getSimpleValue(d, "/items/item/minage", "value"));

            result.UsersRated = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/usersrated", "value"));
            result.Average = double.Parse(getSimpleValue(d, "/items/item/statistics/ratings/average", "value"),System.Globalization.NumberStyles.AllowDecimalPoint,System.Globalization.NumberFormatInfo.InvariantInfo);//.Replace(".",","));
            result.StdDev = double.Parse(getSimpleValue(d, "/items/item/statistics/ratings/stddev", "value"), System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);//.Replace(".", ","));
            result.Owned = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/owned", "value"));
            result.Trading = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/trading", "value"));
            result.Wanting = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/wanting", "value"));
            result.Wishing = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/wishing", "value"));
            result.NumComments = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/numcomments", "value"));

            //Player count votes
            var numPlayersNodes = d.SelectNodes("/items/item/poll[@name='suggested_numplayers']/results/result");
            if (numPlayersNodes != null)
            {
                foreach (XmlNode node in numPlayersNodes)
                {
                    int numPlayers;
                    if (!int.TryParse(node.ParentNode.Attributes["numplayers"].Value, out numPlayers))
                        numPlayers = -1;

                    var votes = int.Parse(node.Attributes["numvotes"].Value);
                    if (node.Attributes["value"].Value.Equals("Best")){
                        result.NumPlayersBest.Add(numPlayers, votes);
                    }
                    else if (node.Attributes["value"].Value.Equals("Recommended")){
                        result.NumPlayersRecommended.Add(numPlayers, votes);
                    }
                    else{
                        result.NumPlayersNotRecommended.Add(numPlayers, votes);
                    }
                }
            }

            //Suggested player age
            var playerAgeNodes = d.SelectNodes("/items/item/poll[@name='suggested_playerage']/results/result");
            if (playerAgeNodes != null)
            {
                foreach (XmlNode node in playerAgeNodes)
                {
                    int age;
                    if (!int.TryParse(node.Attributes["value"].Value, out age))
                        age = -1;
                    var votes = int.Parse(node.Attributes["numvotes"].Value);
                    result.SuggestedPlayerAge.Add(age,votes);
                }
            }

            //Categories
            var categoriesNodes = d.SelectNodes("/items/item/link[@type='boardgamecategory']");
            if (categoriesNodes != null)
                foreach (XmlNode node in categoriesNodes)
                {
                    int id = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Categories.Add(id);
                    categoryNames[id] = name;
                }

            var mechanicsNodes = d.SelectNodes("/items/item/link[@type='boardgamemechanic']");
            if (mechanicsNodes != null)
                foreach (XmlNode node in mechanicsNodes)
                {
                    int id = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Mechanics.Add(id);
                    mechanicNames[id] = name;
                }

            // board game implementation
            var implementationNodes = d.SelectNodes("/items/item/link[@type='boardgameimplementation']");
            if (implementationNodes != null)
                foreach (XmlNode node in implementationNodes)
                {
                    int id = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Implementations.Add(id);
                    implementationNames[id] = name;
                }

            // board game family
            var familyNodes = d.SelectNodes("/items/item/link[@type='boardgamefamily']");
            if (familyNodes != null)
                foreach (XmlNode node in familyNodes)
                {
                    int id = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Families.Add(id);
                    familyNames[id] = name;
                }

            // designer
            var designerNodes = d.SelectNodes("/items/item/link[@type='boardgamedesigner']");
            if (designerNodes != null)
                foreach (XmlNode node in designerNodes)
                {
                    int id = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Designers.Add(id);
                    designerNames[id] = name;
                }

            // artist
            var artistNodes = d.SelectNodes("/items/item/link[@type='boardgameartist']");
            if (artistNodes != null)
                foreach (XmlNode node in artistNodes)
                {
                    int id = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Artists.Add(id);
                    artistNames[id] = name;
                }

            // publisher
            var publisherNodes = d.SelectNodes("/items/item/link[@type='boardgamepublisher']");
            if (publisherNodes != null)
                foreach (XmlNode node in publisherNodes)
                {
                    int id = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Publishers.Add(id);
                    publisherNames[id] = name;
                }

            return result;
        }
Ejemplo n.º 2
0
        public static Boardgame ParseXml(XmlDocument d)
        {
            if (!d.FirstChild.NextSibling.HasChildNodes)
            {
                return(null);
            }
            var result = new Boardgame();

            //Simple fields
            result.Id            = int.Parse(getSimpleValue(d, "/items/item", "id"));
            result.Name          = getSimpleValue(d, "/items/item/name[@type='primary']", "value").Replace(';', ':').Replace('\n', ' ').Replace('\r', ' ');
            result.YearPublished = int.Parse(getSimpleValue(d, "/items/item/yearpublished", "value"));
            result.MinPlayers    = int.Parse(getSimpleValue(d, "/items/item/minplayers", "value"));
            result.MaxPlayers    = int.Parse(getSimpleValue(d, "/items/item/maxplayers", "value"));
            result.PlayingTime   = int.Parse(getSimpleValue(d, "/items/item/playingtime", "value"));
            result.MinAge        = int.Parse(getSimpleValue(d, "/items/item/minage", "value"));

            result.UsersRated  = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/usersrated", "value"));
            result.Average     = double.Parse(getSimpleValue(d, "/items/item/statistics/ratings/average", "value"), System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo); //.Replace(".",","));
            result.StdDev      = double.Parse(getSimpleValue(d, "/items/item/statistics/ratings/stddev", "value"), System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);  //.Replace(".", ","));
            result.Owned       = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/owned", "value"));
            result.Trading     = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/trading", "value"));
            result.Wanting     = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/wanting", "value"));
            result.Wishing     = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/wishing", "value"));
            result.NumComments = int.Parse(getSimpleValue(d, "/items/item/statistics/ratings/numcomments", "value"));

            //Player count votes
            var numPlayersNodes = d.SelectNodes("/items/item/poll[@name='suggested_numplayers']/results/result");

            if (numPlayersNodes != null)
            {
                foreach (XmlNode node in numPlayersNodes)
                {
                    int numPlayers;
                    if (!int.TryParse(node.ParentNode.Attributes["numplayers"].Value, out numPlayers))
                    {
                        numPlayers = -1;
                    }

                    var votes = int.Parse(node.Attributes["numvotes"].Value);
                    if (node.Attributes["value"].Value.Equals("Best"))
                    {
                        result.NumPlayersBest.Add(numPlayers, votes);
                    }
                    else if (node.Attributes["value"].Value.Equals("Recommended"))
                    {
                        result.NumPlayersRecommended.Add(numPlayers, votes);
                    }
                    else
                    {
                        result.NumPlayersNotRecommended.Add(numPlayers, votes);
                    }
                }
            }

            //Suggested player age
            var playerAgeNodes = d.SelectNodes("/items/item/poll[@name='suggested_playerage']/results/result");

            if (playerAgeNodes != null)
            {
                foreach (XmlNode node in playerAgeNodes)
                {
                    int age;
                    if (!int.TryParse(node.Attributes["value"].Value, out age))
                    {
                        age = -1;
                    }
                    var votes = int.Parse(node.Attributes["numvotes"].Value);
                    result.SuggestedPlayerAge.Add(age, votes);
                }
            }

            //Categories
            var categoriesNodes = d.SelectNodes("/items/item/link[@type='boardgamecategory']");

            if (categoriesNodes != null)
            {
                foreach (XmlNode node in categoriesNodes)
                {
                    int    id   = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Categories.Add(id);
                    categoryNames[id] = name;
                }
            }

            var mechanicsNodes = d.SelectNodes("/items/item/link[@type='boardgamemechanic']");

            if (mechanicsNodes != null)
            {
                foreach (XmlNode node in mechanicsNodes)
                {
                    int    id   = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Mechanics.Add(id);
                    mechanicNames[id] = name;
                }
            }

            // board game implementation
            var implementationNodes = d.SelectNodes("/items/item/link[@type='boardgameimplementation']");

            if (implementationNodes != null)
            {
                foreach (XmlNode node in implementationNodes)
                {
                    int    id   = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Implementations.Add(id);
                    implementationNames[id] = name;
                }
            }

            // board game family
            var familyNodes = d.SelectNodes("/items/item/link[@type='boardgamefamily']");

            if (familyNodes != null)
            {
                foreach (XmlNode node in familyNodes)
                {
                    int    id   = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Families.Add(id);
                    familyNames[id] = name;
                }
            }

            // designer
            var designerNodes = d.SelectNodes("/items/item/link[@type='boardgamedesigner']");

            if (designerNodes != null)
            {
                foreach (XmlNode node in designerNodes)
                {
                    int    id   = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Designers.Add(id);
                    designerNames[id] = name;
                }
            }

            // artist
            var artistNodes = d.SelectNodes("/items/item/link[@type='boardgameartist']");

            if (artistNodes != null)
            {
                foreach (XmlNode node in artistNodes)
                {
                    int    id   = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Artists.Add(id);
                    artistNames[id] = name;
                }
            }

            // publisher
            var publisherNodes = d.SelectNodes("/items/item/link[@type='boardgamepublisher']");

            if (publisherNodes != null)
            {
                foreach (XmlNode node in publisherNodes)
                {
                    int    id   = int.Parse(node.Attributes["id"].Value);
                    string name = node.Attributes["value"].Value;
                    result.Publishers.Add(id);
                    publisherNames[id] = name;
                }
            }

            return(result);
        }