score:2

Accepted answer

I corrected your first attempt (LINQ). It returns first <PName type="Patient"> from xml in question.

IEnumerable<XElement> tests =
    from el in root.Element("PList").Elements("PName")
    let c = el.Descendants("classification")
    where c.Where(x => x.Attribute("classification").Value == "paymenttype"
                    && x.Attribute("category").Value == "Wallet").Any()
    select el;

Then you can iterate tests and extract what you want.

foreach (var el in tests)
{
    Console.WriteLine(
        el.Element("properties")
          .Element("PName")
          .Attribute("title")
          .Value);
}

I also corrected your second attempt (XPath). It will return title value of <PName title="Joe Beom" PId="1234">.

var query = @"//PName[Details/classification[@classification='paymenttype' and @category='Wallet']]/@title";
foreach (XmlNode n in docs.SelectNodes(query))
{
    Console.WriteLine(n.Value);
}

Related Articles