Reputation: 1323
I have a requirement to specify wild card in the following xpath
Field[@name="/Root/Table[i]/FirstName"]
Basically the "i" would be a variable which can have either a GUID or a running number. I would like to pick up all elements that basically have the attribute pattern
"/Root/Table[*]/FirstName"
i.e. starting with "/Root/Table[" and ending with "]/FirstName". Any ideas as to how this can be done ?
Here is a sample payload:
<Package>
<Input>
<Data id="36e9f0fe3f8d4508ac20710e07cfddd4">
<Input>
<Field name="/Root/Table[1]/FirstName">Thomas</Field>
</Input>
</Data>
</Input>
</Package>
Upvotes: 0
Views: 234
Reputation: 101682
You should be able to do this using starts-with()
and a makeshift ends-with()
(since XPath 1.0 doesn't actually have an ends-with()
function):
//*[starts-with(@name, '/Root/Table[') and
substring(@name, string-length(@name) - 11 + 1) = ']/FirstName']
Here, 11
is the length of ]/FirstName
.
Upvotes: 1