Following @MiffTheFox answer you can use XPath with LINQ to XML . Here is an example based on your sample data.
1) First, the namespaces you will need:
using System.Linq; using System.Xml; using System.Xml.Linq; using System.Xml.XPath;
2) Load the XML document in XElement :
XElement rootElement = XElement.Parse(xml);
3) Determine the XPath location path:
// For example, to locate the 'MimeType' element whose 'Extension' // child element has the value '.aam': // // ./MimeType[Extension='.aam'] string extension = ".aam"; string locationPath = String.Format("./MimeType[Extension='{0}']", extension);
4) Move the path to XPathSelectElement() to select the element of interest:
XElement selectedElement = rootElement.XPathSelectElement(locationPath);
5) Finally, retrieve the MimeType value associated with the extension:
var mimeType = (string)selectedElement.Element("Value");
DavidRR
source share