I want to read my xml and then in c# code generate textblock to add all datas in their textlock, make something like a table or list.
My xml is:
<?xml version="1.0"?>
<players>
<player>
<id>10101</id>
<name>Ricardo Ferreira Rodrigues</name>
<shirtnumber>1</shirtnumber>
<position>Guarda Redes</position>
</player>
<player>
<id>10102</id>
<name>Manuel Lopes</name>
<shirtnumber>2</shirtnumber>
<position>fixo</position>
</player>
</players>
And my code is:
private async void LoadXml()
{
try
{
StorageFolder storageFolder = Package.Current.InstalledLocation;
StorageFile storageFile = await storageFolder.GetFileAsync("players2.xml");
string xml = await FileIO.ReadTextAsync(storageFile, Windows.Storage.Streams.UnicodeEncoding.Utf8);
var doc = XDocument.Parse(xml);
var rootNode = doc.Root;
foreach (var child in rootNode.Descendants("player"))
{
//I try this
//TextBlock txtnome = new TextBlock();
//TextBlock txtshirtnumber = new TextBlock();
//TextBlock txtposition = new TextBlock();
txtnome.Text = (string)doc.Root.Element("name");
txtshirtnumber.Text = (string)doc.Root.Element("shirtnumber");
txtposition.Text = (string)doc.Root.Element("position");
}
}
but this textblock i make it and i want the code to generate then because I will need to add lot of players.
My Erro is "values cannot be null".
Someone can help me?