我有一些像下面這樣的 xml 文件<ref-list><ref id="ref1"><label>(1)</label> <mixed-citation publication-type="book" publication-format="print"><person-group person-group-type="author"><string-name><given-names>C.N.</given-names> <surname>Srinivasiengar</surname></string-name></person-group>, <source>The History of Ancient Indian Mathematics</source>. <publisher-loc>Calcutta</publisher-loc>: <publisher-name>The World Press</publisher-name>, <year>1967</year>.</mixed-citation></ref><ref id="ref2"><label>(2)</label> <mixed-citation publication-type="periodical" publication-format="print"><person-group person-group-type="author"><string-name><given-names>F.J.M.</given-names> <surname>Barning</surname></string-name></person-group>, <article-title>On Pythagorean and quasi-Pythagorean triangles and a generation process with the help of unimodular matrices</article-title>, <source type="IEEE">(Dutch) Math. Centrum Amsterdam Afd. Zuivere Wisk, ZW-011</source>, <year>1963</year>.</mixed-citation></ref>我正在嘗試檢查具有屬性Publication-type="thesis"的節(jié)點(diǎn)混合引用,并檢查它是否有任何名為機(jī)構(gòu)的子元素,其中沒有任何名為content-type 的屬性?;旧嫌胁荒芟袢魏喂?jié)點(diǎn)在混合引出版物型=“論文”但可以有。<institution>...</institution><institution content-type="...">...</institution>這是我試過的XDocument doc=XDocument.Load(xmlfile);var thesiss=doc.Descendants("mixed-citation") .Where(a=>a.Attribute("publication-type").Value=="thesis") .Where(a=>a.Descendants("institution").Any() && !a.Descendants("institution").Attributes("content-type").Any()) .Select(a=>a.Parent.Attribute("id"));foreach (var element in thesiss) { Console.WriteLine("Check "+element);}但它并不完全按照我想要的方式工作。上面給出的樣本應(yīng)該給出輸出Check id="ref6"Check id="ref8"但它只顯示Check id="ref8"。請(qǐng)幫忙。
1 回答

白衣非少年
TA貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個(gè)贊
將您的查詢更改為:
var thesiss = doc.Descendants("mixed-citation")
.Where(a => a.Attribute("publication-type").Value == "thesis")
.Where(a => !a.Descendants("institution").All(d => d.Attribute("content-type") != null))
.Select(a => a.Parent.Attribute("id"));
這應(yīng)該會(huì)產(chǎn)生想要的結(jié)果。
- 1 回答
- 0 關(guān)注
- 155 瀏覽
添加回答
舉報(bào)
0/150
提交
取消