Brilliant! Thank you very much for you assistance :)
That solves my problem in a much cleaner and easier way. It's ended up looking like this:
def rtv = { xmlSource, tagName, newValue ->
regex = "<$tagName>[^<]*</$tagName>"
replacement = "<$tagName>${newValue}</$tagName>"
xmlSource = xmlSource.replaceAll(regex, replacement)
return xmlSource
}
input = rtv( input, "Mobiltlf", "32165487" )
input = rtv( input, "E-mail-adresse", "[email protected]" )
println input
Since I'm giving this to our testers for use in their testing tool SoapUI, I've tried to "wrap" it, to make it easier for them to copy and paste.
This is good enough for my purpose, but it would be perfect if we could add one more "twist"
Let's say the input had this in it...
<Mobiltlf type="national" anotherattribute="value"></Mobiltlf>
...and we wanted to retain thos two attributes even though we replaced the value. Is there a way to use regexp for that too?