我正在尝试阅读此 xml:
<player>
<id>10101</id>
<name>Ricardo Ferreira Rodrigues</name>
<shirtnumber>1</shirtnumber>
<position>Guarda Redes</position>
<realteam>5</realteam>
</player>
我有这个代码:
private async void LoadXml()
{
try
{
StorageFolder storageFolder = Package.Current.InstalledLocation;
StorageFile storageFile = await storageFolder.GetFileAsync("/users/1101046102/xml/players.xml");
string xml = await FileIO.ReadTextAsync(storageFile, Windows.Storage.Streams.UnicodeEncoding.Utf8);
var doc = XDocument.Parse(xml);
txtnome.Text = (string)doc.Root.Element("name");
txtshirtnumber.Text = (string)doc.Root.Element("shirtnumber");
txtposition.Text = (string)doc.Root.Element("position");
}
catch (Exception ex)
{
XmlTextBlock.Text = ex.Message;
}
}
我得到这个“值不属于预期范围异常”。有人可以告诉我为什么吗?