If so, create a couple of classes with Xml attributes:
Code:
namespace CG
{
#region Using Directives
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
#endregion Using Directives
///<summary>
/// Serialization class used to read the teamtable
///</summary>
[Serializable]
[XmlType( AnonymousType = true )]
[XmlRoot( ElementName = "TeamTable", Namespace = "", IsNullable = false )]
publicclassTeams
{
///<summary/>
publicstaticTeams Open( string configFile )
{
var serializer = newXmlSerializer( typeof( Teams ) );
using ( var reader = XmlReader.Create( configFile ) )
{
return ( Teams ) serializer.Deserialize( reader );
}
}
///<remarks/>
[XmlElement( "TeamRow", IsNullable = false )]
publicTeam [ ] Rows
{
get
{
return _rows.ToArray( );
}
set
{
if ( null == _rows )
{
_rows = newList<Team>( );
}
_rows.AddRange( value );
}
}
privateList<Team> _rows = newList<Team>( );
}
///<remarks/>
[Serializable]
[XmlType( AnonymousType = true )]
publicclassTeam
{
///<remarks/>
[XmlAttribute( AttributeName = "Id" )]
publicint Id { get { return _id; } set { _id = value; } }
///<remarks/>
[XmlAttribute( AttributeName = "Name" )]
publicstring Name { get { return _name; } set { _name = value; } }
privateint _id;
privatestring _name;
}
}
Then loading up the xml is:
Code:
var teamList = newList<Team>( );
// Loads the xml into a Teams instance
var teams = Teams.Open("teams.xml");
// Retrieve the TeamRows
teamList.AddRange( teams.Rows );
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.