xpathFind nodes that have a specific attribute


Syntax

  1. Inside a specific node
    • /path to/element[@attribute_name]
  2. Anywhere in the document
    • //*[@attribute_name]
  3. Inside a specific node with some value
    • /path to/element[@attribute_name='search value']
    • /path to/element[@attribute_name="search value"]
  4. Anywhere in the document with some value
    • //*[@attribute_name='search string']
    • //*[@attribute_name="search string"]

Parameters

Selectorfunction
@attribute_nameIt selects the attribute value for a node, if present

Remarks

Using [@attribute_name] we can select nodes that have the attribute irrespective of the value.

We can use any of the functions or combination of the functions such as starts-with and lowercase, for example, with this selector to suit our needs.