Windows Phone に Visual Studio を使用していますが、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>