我需要像下面这样的输出,我该怎么做?
name1
title1
title2
name2
title1
title2
在那个 for 循环中,我必须显示标题。在这里,我使用了以下代码,这意味着我收到以下错误:
'char' does not contain a definition for 'Attribute' and no extension method 'Attribute' accepting a first argument of type 'char' could be found (are you missing a using directive or an assembly reference
如何解决上述错误以及如何在 for 循环中编写条件以显示标题?
我用过这段代码:
XmlSerializer serializer = new XmlSerializer(typeof(Notchs));
XDocument xmlDoc = XDocument.Parse(dataInXmlFile);
var Categories = (from Category in xmlDoc.Descendants("Category")
select new Notch()
{
name = (string)Category.Attribute("name"),
title = Category.Elements("Articles").Elements("article").ToString()
}).ToList();
foreach(var doc in Categories)
{
foreach(var sec in doc.title)
{
sec.Attribute("title").Value.ToList(),
}
}
NotchsList.ItemsSource = Categories.ToList();
XML
<Categories>
<Category name="notchbolly">
<Articles>
<article articleid="170" title="Colour And Vibrancy Are Part Of Our DNA">...</ article>
<article articleid="187" title="German chef gets saucy!!">...</article>
<article articleid="2004" title="Meet-the-Face-of-Compassion">...</article>
<article articleid="2005" title="Dutt’s-family-gets-together!">...</article>
<article articleid="1933" title="NOTCH easy to do recipe- Mushroom Risotto with truffles">...</article>
<article articleid="1934" title="NOTCH easy to do recipe- Lobster with Black ink Linguini Arabiatta">...</article>
<article articleid="1935" title="Yash Birla- 100% Living">...</article>
</Articles>
</Category>
<Category name="notchfashion">
<Articles>
<article articleid="81" title="Making Headlines">...</article>
<article articleid="99" title="Ladakh through my Lens">...</article>
<article articleid="689" title="A-Family-Affair">...</article>
<article articleid="2264" title="Sushmita-back-with-Manav?">...</article>
<article articleid="70" title="NOTCH- Making of the cover- Farhan Akhtar & Javed Akhtar">...</article>
<article articleid="78" title="NOTCH easy to do recipe- Aubergine Carpaccio">... </article>
<article articleid="1935" title="Yash Birla- 100% Living">...</article>
</Articles>
</Category>