James A. Rosen
James A. Rosen

Reputation: 65242

How can I get wildcards to work in XPath attribute value matching?

I have the following XML:

<root>
  <foo>
    <bar type="a whole bunch of stuff, then a magic string: MUPPET" />
    <value>my Muppet value</value>
  </foo>
  <foo>
    <bar type="some other stuff, then a different magic string: GREMLIN" />
    <value>my Gremlin value</value>
  </foo>
</root>

I'd like to build an XPath query that returns "my Muppet value" (the string) given the magic string "MUPPET". My guess was:

/root/foo[contains(bar/@type,'MUPPET')]/value/text()

but that doesn't seem to work. I'm really not sure whether that contains(x,y) operator allows a query as the first parameter. As a side issue, I'm not sure whether I need the text() on the end.

Any help?

Upvotes: 5

Views: 9395

Answers (2)

Baget
Baget

Reputation: 3346

I just checked with this Online XPATH Evaluators and it is working fine:

http://www.mizar.dk/XPath/Default.aspx

Upvotes: 5

lavinio
lavinio

Reputation: 24309

Are you sure you don't have a namespace issue with your XPath?

Upvotes: 0

Related Questions