C# 通过同一节点中的其他数据获取节点中的特定数据

C# 通过同一节点中的其他数据获取节点中的特定数据,c#,xml,C#,Xml,我得到的XML是这样的: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <!--Some comment--> <Databook> <Note> <Name>Camera2 made a snapshoot #243</Name> <Value>Camera2_snapshoot-2013-09-06_21-47-35.png

我得到的XML是这样的:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--Some comment-->
<Databook>
  <Note>
    <Name>Camera2 made a snapshoot #243</Name>
    <Value>Camera2_snapshoot-2013-09-06_21-47-35.png</Value>
  </Note>
  <Note>
    <Name>Camera1 made a snapshoot #244</Name>
    <Value>Camera1_snapshoot-2013-09-06_21-47-39.png</Value>
  </Note>
</Databook>

如果您只想要
的值,其中
名称
等于

尝试:

string xmlfile = string.Format("XML/Diary/" + day);
XDocument dailyXML = XDocument.Load(xmlfile);

XElement Contact = (from xml2 in dailyXML.Descendants("Note")
                    where xml2.Element("Name").Value == item
                    select xml2).FirstOrDefault();
string result = (from xml2 in dailyXML.Descendants("Note")
                           where xml2.Element("Name").Value == item
                           select xml2.Element("Value").Value).FirstOrDefault();
string result = dailyXML.Descendants("Note")
                        .Where(n => n.Element("Name").Value == item)
                        .FirstOrDefault(n => n.Element("Value").Value);