0

Is is possible to select nodes IF they have a certain attribute? The nodes I require all have a "data-rel" attribute. I want to select only the nodes that have that attribute, irrespective of the "data-rel" attributes value.

<a href="/someurl.php" data-rel="..."> 

I've tried ...

List<HtmlAgilityPack.HtmlNode> groups = doc.DocumentNode.SelectNodes("//a[contains(@data-rel)]").Distinct().ToList(); 

... to no avail.

1
  • 1
    As a matter of interest, was there anything in the specification of contains() that misled you into thinking this is what the function did, or were you just guessing? As the current editor of the spec, I'm interested to know why people go so badly wrong. Commented Jul 20, 2013 at 14:43

1 Answer 1

2

Try //a[@data-rel]

See http://www.w3schools.com/xpath/xpath_syntax.asp

//title[@lang] Selects all the title elements that have an attribute named lang 

Reference http://www.w3.org/TR/xpath/#path-abbrev

employee[@secretary and @assistant] selects all the employee children of the context node that have both a secretary attribute and an assistant attribute 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.