91

Is there an xpath way to find a node that has a given attribute whose value contains a given string?

For example I have an xml document and want to find a node where the address attribute contains the string Downing, so that I could find the following node:

<person name="blair" address="10 Downing St. London"/>
1

1 Answer 1

163
select="//*[contains(@address,'Downing')]"
Sign up to request clarification or add additional context in comments.

4 Comments

Tested with Notepad++ XML Tools, returns the node fine. Good job.
Remember to avoid the '//' if possible. :-) Good job though.
@Jweede yeah, I know. But as the node wasn't specified, I assumed that he wants every node with that attribute.
Been looking all over for a way to do "like" style searching for the value of an attribute. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.