我想阅读下面的 XML 并按以下顺序打印输出。你能帮忙查询如何绑定图像吗?
<?xml version="1.0" encoding="utf-8"?>
<Book>
<L1 id="100">
<Subjects>
<subject>
<thumb_image>
<image url= url="http://dev2.merceed.jpeg1"/>
<thumb_image>
</subject>
<subject>
<thumb_image>
<image url= url="http://dev2.merceed.jpeg2"/>
<thumb_image>
</subject>
<subject>
<thumb_image>
<image url= url="http://dev2.merceed.jpeg3"/>
<thumb_image>
</subject>
</Subjects>
</L1>
<L2 id="200">
<Subjects>
<subject>
<thumb_image>
<image url= url="http://dev2.merceed.jpeg"/1>
<thumb_image>
</subject>
<subject>
<thumb_image>
<image url= url="http://dev2.merceed.jpeg2"/>
<thumb_image>
</subject>
<subject>
<thumb_image>
<image url= url="http://dev2.merceed.jpeg2"/>
<thumb_image>
</subject>
</Subjects>
</L2>
<Book>
我想要像这样的输出
100
图片1
图片2
图3
......
200
图片11
图12
图13
我正在使用我的代码是
var query = from l in xmlDoc.Descendants("L1")
from subject in l.Descendants("Subjects")
select new Notch
{
name = (string)l.Attribute("id").Value,
SubjectName= l.subject("article").Select(a => (string)a.Attribute("SubjectName")).ToList(),
url = l.Element("article").Elements("thumb_image").Select(x => (string)x.Attribute("url")).ToString()
};
foreach (var result in query)
{
foreach (var titles in result.SubjectName)
{
Console.WriteLine(titles);
}
foreach (var image in category.Image)
{
Console.WriteLine(image);
}
}