XML (Extensible Markup Language) data file (composed of tags as it’s a markup language) to define objects (+attributes) (API basically uses it, RSS feeds and many more things), we can use it to store text-based data.
Before we start, let’s take a look on the example of the XML file I’m using

1

2

3

4

5

6

7

8

9

10

11

<?xml version="1.0"encoding="utf-8"?>

<writers>

<writer>

<name>Med Anas</name>

<email>medanasbo@loovus.org</email>

</writer>

<writer>

<name>Daan</name>

<email>daan@loovus.org</email>

</writer>

</writers>

Okay, create a new Windows Phone project, give it a name, go to the main page and add this XAML code

1

2

3

4

5

6

7

8

9

10

11

12

<StackPanelx:Name="ContentPanel"Grid.Row="1"Margin="12,0,12,0">

<ListBox Name="TheListBox">

<ListBox.ItemTemplate>

<DataTemplate>

<StackPanel>

<TextBlock Text="{Binding Name}"FontSize="36"/>

<TextBlock Text="{Binding Email}"Foreground="Gray"/>

</StackPanel>

</DataTemplate>

</ListBox.ItemTemplate>

</ListBox>

</StackPanel>

Now add this class (we’ll create an object which will store the data of every object we’ll load from the XML file)

1

2

3

4

5

classWriter

{

publicstringName{set;get;}

publicstringEmail{set;get;}

}

And finally, this code will load the data from the XML file into a list of the Writer class that we’ve just created and will fill the ListBox we used in XAML with this list as an ItemsSource

1

2

3

4

5

6

7

8

XDocument XMLdata=XDocument.Load("XMLdataFILE.xml");

vardataList=from query inXMLdata.Descendants("writer")

selectnewWriter

{

Name=query.Element("name").Value,

Email=query.Element("email").Value

};

TheListBox.ItemsSource=dataList;

And don’t forget to include this namespace

1

using System.Xml.Linq;

Is there a bonus ?
I’m sorry there is no bonus included this time, but I’ll post a tutorial sooner on how to work with JSON (JavaScript Object Notation) data files