我想从 xml 文件中获取标签以在文本块中获取它。
我的代码是:
private async void btnPlantel_Click(object sender, RoutedEventArgs e)
{
try
{
var doc = XDocument.Parse(txtnome.Text);
var doc2 = XDocument.Parse(txtshirtnumber.Text);
StorageFolder storageFolder = Package.Current.InstalledLocation;
StorageFile storageFile = await storageFolder.GetFileAsync("players2.xml");
txtnome.Text = await FileIO.ReadTextAsync(storageFile, Windows.Storage.Streams.UnicodeEncoding.Utf8);
txtshirtnumber.Text = await FileIO.ReadTextAsync(storageFile, Windows.Storage.Streams.UnicodeEncoding.Utf8);
txtnome.Text = (string)doc.Root.Element("name");
txtshirtnumber.Text = (string)doc2.Root.Element("shirtnumber");
}
catch (Exception ex)
{
txterror.Text = ex.Message;
}
}
和xml是:
<player>
<name>Ricardo Ferreira Rodrigues</name>
<shirtnumber>1</shirtnumber>
</player>
但我在 txtbox 中得到的只是错误“缺少根元素”。有人可以帮助我吗?