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.
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.
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> |
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> |
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> |
I have attached the zipped conversion app sample code. It contains the following: