XPath Find Elements with specific Attribute

Get all elements that have the style attribute => “//*[@style]”

Get all elements where style equals bold => “//*[@style=’bold’]”

Get all elements where style contains the string red => “//*[contains(@style,’red’)]”

Get all customer elements that have the age attribute => “//customer[@age]”

Get all customer that have both age and gender attributes => “//customer[@age and @gender]”

4 thoughts on “XPath Find Elements with specific Attribute

  • I found your site on technorati and read a few of your other posts. Keep up the good work. I just added your RSS feed to my Google News Reader. Looking forward to reading more from you down the road!

    Like

  • Thanks, I am glad you are getting some use out of my blog. I really just started it in order to consolidate the things I learn each day as I develop so I wouldn't have to chase down or keep track of each tutorial, forum, or blog I found answers on. Hopefully it will one day be a one stop resource for anything (.Net, C#, HTML/CSS, XML, etc.) development related.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s