tags:

views:

352

answers:

1

this is what I want...

Assuming I'm trying to get at the value of 'B'

<tree>
<nodea>
<nodeb>
A=foo;
B=bar;
C=goo;
</nodeb>
</nodea>
</tree>

the following is magical syntax which would make sense... I'm looking for something comparable that actually works :)

string = "./nodea/nodeb/[ REGEX( 'B=(.*?);' ) ]/ $1"

Is there anything like this in any java xpath library?

+4  A: 

XPath 2.0 adds regular expressions. Something like this ought to do what you want, I think:

fn:replace(./nodea/nodeb, ".*B=(.*?);.*", "$1")
Jay Kominek
I believe you're right! (though in the interest of someone finding this and trying to use it in the future, please edit your answer and replace your regexp with this...".*?B=(.*?);.*" otherwise the thing get hungry and skips all the valuable bits :)
Dr.Dredel
which library should I be using? it seems that the javax library doesn't know what to do with an xpath string that starts with "fn:replace("
Dr.Dredel
Looks like no version of Java comes with XPath 2.0. :( I believe you'll need to use Saxon.
Jay Kominek