tags:

views:

813

answers:

3

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?

+1  A: 

I just check with 2 Online XPATH Evaluators and it is working fine:

http://b-cage.net/code/web/xpath-evaluator.html

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

Baget
You're entirely correct; they sure do! And that answers my question about /text(), too. Must be a problem with IBM's XPath engine in Eclipse. Hrm.
James A. Rosen
A: 

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

lavinio
Don't think so; I think it's a problem with IBM's BIRT reporting tool, not the XPath query. If I change the query from "./foo[contains(bar/@type,'MUPPET')]/value/text()" to "." I still get nothing. Certainly "." should match _something_...
James A. Rosen
A: 

Thanks (Baget) for the XPath Evaluator links and also thanks (Gaius) for the Xpath which helped me solve my query.. :)