Alex Rivera | Logout

use wildcard to match attribute in xpath

Asked 2012-07-09T10:19:45.453
8

I am working on an asp.net application based on .net 2.0.

And I meet some problems when I process the XML.

Suppose I have XML like this:

<person name="xxxyx" age="32" />

<person name="zzz" age="32" />

<person name="yyyxx" age="32" />

Now I want to select the person whose name contains yx

How do I use xpath to implement it?

I only know this expression will match the person whose name is exactly "yx":

"//person[name='yx'"]"

How to make the fuzzy search?

BTW, any idea to sort the matched person by the specified attribute like "name"?

Edit
Report

1 Answer

8

Use the contains() function.

//person[contains(@name, 'yx')]

Also, note you need @ in front of name since it's an attribute.

Demo.

answered 2012-07-09T10:22:40.927

Your Answer