-1

Consider the snippet below:

var xpath = "//i[@a='1']";
var item = new XElement("i",
    new XAttribute("a", "1"),
    new XAttribute("b", "2"),
    new XAttribute("c", "3"));

Console.WriteLine(item); // <i a="1" b="2" c="3" />
Console.WriteLine("{0} = {1}", xpath, item.XPathSelectElements(xpath).Any());

I was expecting the .Any() result to be true, but I keep getting false.

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162

2 Answers2

0

Problem is with your root element.

You can also test it with this xml

var item = new XDocument(new XElement("i",
                new XAttribute("a", "1"),
                new XAttribute("b", "2"),
                new XAttribute("c", "3")));

This will return TRUE

Eser
  • 12,346
  • 1
  • 22
  • 32
0

Using self::i[@a='1'] or adding that XElement into a XDocument did the trick.

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162