Up Scoring goals with DevForce

Scoring goals: Create an XML conversion app

Last modified on May 12, 2011 15:22

To write the conversion app, I took the following steps:
1. Parse the xml files using XDocument from .NET Framework 4.

2. Add an ADO.Net Entity Data Model, built with the Fantasy Soccer database, into the project. Use DevForce code generation to generate DevForce entities/business objects. These steps can be quickly learned by watching this DevForce Silverlight tutorial

3. Use DevForce entitymanager to add the clubs, players and game stats into the database. Note that the solution also contains a method to delete all the records in the database.



Snippets

Here are snippets of 3 of my xml files and how they are structured. Each object’s element matches up directly with its corresponding SQL database table’s fields.

Clubs.xml

XML
<Clubs>
  <Club>
    <ClubID>0</ClubID>
    <ClubName>Liverpool</ClubName>
    <GoalsScored>0</GoalsScored>
    <GoalsAllowed>0</GoalsAllowed>
    <TotalYellowCard>0</TotalYellowCard>
    <TotalRedCard>0</TotalRedCard>
    <Players>
      <PlayerID>0</PlayerID>
      <PlayerID>4</PlayerID>
      <PlayerID>32</PlayerID>
      <!--More Players here-->
    </Players>
  </Club>
</Clubs>

Players.xml

XML
<Players>
  <Player>
    <PlayerID>0</PlayerID>
    <PlayerName>Steven Gerrard</PlayerName>
    <ClubID>0</ClubID>
    <PlayerPos>Central Midfielder</PlayerPos>
    <GameStats>
      <GameStatID>115</GameStatID>
      <GameStatID>178</GameStatID>
      <GameStatID>686</GameStatID>
      <GameStatID>1031</GameStatID>
      <GameStatID>1232</GameStatID>
      <GameStatID>1720</GameStatID>
<!--More GameStats here-->
    </GameStats>
  </Player>
</Players>

GameStats.xml

XML
<GameStats>
  <GameStat>
    <GameID>0</GameID>
    <PlayerID>7</PlayerID>
    <MatchOpp>WBA</MatchOpp>
    <Goal>0</Goal>
    <OwnGoal>0</OwnGoal>
    <Assist>0</Assist>
    <Shots>0</Shots>
    <SOT>0</SOT>
    <CleanSheet>1</CleanSheet>
    <Save>1</Save>
    <PKSave>0</PKSave>
    <YellowCard>0</YellowCard>
    <RedCard>0</RedCard>
  </GameStat>
</GameStats>

Download sample

I have attached the zipped conversion app sample code. It contains the following: 

  1. The solution.
  2. The three xml files.
  3. Two FantasySoccer SQL database. One that has not been populated with records and one that has.

Prerequisites

Created by DevForce on February 04, 2011 11:59

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade