【发布时间】:2016-08-18 10:38:49
【问题描述】:
我有以下 xml:
<century>
<question>What is silvia</question>
<answer>silvia is artificial intelligence</answer>
<question>What is your name</question>
<answer>my name is RAMESH</answer>
</century>
我想根据使用 linq 的给定问题获得答案。我该怎么做?
当前代码:
string textToSearch = "When did AI research start";
XDocument doc = XDocument.Load(@"D:\SILVIA\New task\FinalXml.xml");
var q = doc.Descendants("CenturySoft")
.Descendants("question")
.Where(item => item.Value == textToSearch)
.Select(item => item.NextNode)
.FirstOrDefault();
我得到带有<answer> 标签的输出。怎么去掉?
【问题讨论】:
标签: c# linq linq-to-xml