我想在<author>
属性中阅读<incollection>
。元素名称相同但数量不同。
如何阅读<incollection>
的作者?请帮忙阅读
第一个<incollection>
有三位作者,第二位<incollection>
有六位作者。
<incollection mdate="2013-09-10" key="series/cogtech/HuangEV04">
<author>Zhisheng Huang</author>
<author>Anton Elins</author>
<author>Cees T. Visser</author>
<title>STEP: a Scripting Language for Embodied Agents.</title>
<pages>87-110</pages>
<year>2004</year>
<booktitle>Life-like characters</booktitle>
<crossref>series/cogtech/354000867</crossref>
<url>db/series/cogtech/354000867.html#HuangEV04</url>
</incollection>
<incollection mdate="2013-09-10" key="series/cogtech/PaivaPMMVS04">
<author>Ana Paiva</author>
<author>Rui Prada</author>
<author>Isabel Machado</author>
<author>Carlos Martinho</author>
<author>Marco Vala</author>
<author>Andr Silva</author>
<title>Playing with Agents-Agents in Social and Dramatic Games.</title>
<pages>361-376</pages>
<year>2004</year>
<booktitle>Life-like characters</booktitle>
<crossref>series/cogtech/354000867</crossref>
<url>db/series/cogtech/354000867.html#PaivaPMMVS04</url>
</incollection>
答案 0 :(得分:1)
在LINQ to XML中:
var xd = XDocument.Load(@"C:\myXml.xml");
var authors = xd.Root
.Elements("incollection")
.Elements("author")
.Select (x => x.Value);
foreach (var x in authors)
Console.WriteLine (x);
从两个收集中打印所有作者的列表。
但是如果你想按密钥过滤它,你的查询就是这样的:
var authorsFiltered = xd.Root
.Elements("incollection")
.Where (w => w.Attribute("key").Value.Contains("PaivaPMMVS04"))
.Elements("author")
.Select (x => x.Value);
foreach (var x in authorsFiltered)
Console.WriteLine (x);
这将打印第二个插件中的作者列表
答案 1 :(得分:0)