0
我正在使用visual studio for windows phone,并且当XML数据的父级中存在属性时,我的XML读取器代码不工作。XML读取器在使用xmlns属性时找不到元素
我的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>
不工作数据(注:在根元素 “进” 属性 “的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),这些标签可能会让人们试图回答的问题混淆。 –