xpath Find nodes that have a specific attribute

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any xpath Question?