【发布时间】:2012-12-30 23:18:29
【问题描述】:
我正在使用 Visual Studio for Windows Phone,当 XML 数据的父级中有属性时,我的 XML 阅读器代码不起作用。
我的 C# 代码
namespace youtube_xml
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
}
private void listBox1_Loaded(object sender, RoutedEventArgs e)
{
var element = XElement.Load("Authors.xml");
var authors =
from var in element.Descendants("feed")
select new Authors
{
AuthorName = var.Attribute("scheme").Value,
};
listBoxAuthors.DataContext = authors;
}
public ImageSource GetImage(string path)
{
return new BitmapImage(new Uri(path, UriKind.Relative));
}
}
}
有效的 XML 数据
<?xml version='1.0' encoding='UTF-8'?>
<feed>
<category scheme='http://schemas.google.com/g/2005#kind'/>
</feed>
不是工作数据(注意:根元素“feed”中的属性“xmlns”)
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' >
<category scheme='http://schemas.google.com/g/2005#kind'/>
</feed>
【问题讨论】:
-
我已经更新了标题,希望能更好地反映您的问题(随时恢复/编辑)。下次请在常规桌面版本上尝试相同的代码,以避免添加额外的标签(如 windows-phone-7),这可能会使试图回答的人感到困惑。