Monday 4 January 2010

XPath select attributes containing a string

I needed to find a way to use XPath to select items from within a html document, that would return back to me all UL tags that had an id that contained the word "menu".

To find all the UL's, it is simple enough to do:

//UL


However, to select the id of "menu", I then found:

//ul[@id='menu']


What I ended up with, to find any ULs that contained the word "menu" in the id attribute was:

//ul[contains(@id,'menu')]

No comments:

Post a Comment