Fetch single XML node using LINQ
I have the following XML
<?xml version="1.0" encoding="utf-8"?>
<thesaurus>
<wordblock>
<term type="forbidden" lang="en" termid="27561">
<value>710 REACTOR</value>
<historynote>Prior to May 1993, this was a valid ETDE descriptor.</historynote>
</term>
<dates>
<date type="created">2000-04-12</date>
<date type="modified">2000-04-12</date>
</dates>
<terms>
<term rel="SEE" lang="en" termid="3124" type="valid">
<value>ENRICHED URANIUM REACTORS</value>
</term>
<term rel="SEE" lang="en" termid="3387" type="valid">
<value>FAST REACTORS</value>
</term>
<term rel="SEE" lang="en" termid="3876" type="valid">
<value>GAS COOLED REACTORS</value>
</term>
<term rel="SEE" lang="en" termid="6199" type="valid">
<value>MOBILE REACTORS</value>
</term>
<term rel="SEE" lan开发者_如何学编程g="en" termid="7969" type="valid">
<value>PROPULSION REACTORS</value>
</term>
</terms>
</wordblock>
<wordblock>
[...]
[...]
[...]
</wordblock>
</thesaurus>
I am trying to parse the XML with LINQ and get specific node. In the above e.g., I need to match the value "710 REACTOR", and get the corresponding <terms>
node inside the same <wordblock>
node. I'm not very familiar with the LINQ syntax, so any help is much appreciated.
LINQ wont be much useful in this case. What about using XMLDocument?
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load('your xml');
XmlNode node = xmlDoc.SelectSingleNode("//WordBlock/term[value = '710 REACTOR']");
Try
XDocument xdoc = XDocument.Load(PATH_TO_YOUR_DOCUMENT);
var termNodes = from x in xdoc.Descendants("term")
where x.Element("value").Value == "710 REACTOR"
select x;
精彩评论