tags:

views:

99

answers:

2

Xpath question:

When to use @ with an attribute and when not to. Does it matter? What is the difference

+3  A: 

If you are referring to an attribute, you must use @, otherwise you are referring to an element of that name!

AakashM
+8  A: 

When using //tag[attr] you are selecting all tag elements that have at least one child element named attr. On the other hand, when using //tag[@attr] you are selecting all tag elements that have an attribute named attr.

In sum, you use @ everytime you want to select an attribute. It does matter, because omitting it would select nodes or elements, instead of attributes.

JG