I'm wondering what the most elegant way is in C# to query a STRING that is valid xml using XPath?
Currently, I am doing this (using LINQ):
var el = XElement.Parse(xmlString);
var h2 = el.XPathSelectElement("//h2");
I'm wondering what the most elegant way is in C# to query a STRING that is valid xml using XPath?
Currently, I am doing this (using LINQ):
var el = XElement.Parse(xmlString);
var h2 = el.XPathSelectElement("//h2");
Simple example using Linq to XML :
XDocument doc = XDocument.Parse(someStringContainingXml);
var cats = from node in doc.Descendants("Animal")
where node.Attribute("Species").Value == "Cat"
select node.Attribute("Name").Value;
Much clearer than XPath IMHO...