xmlText() not working (like htmlText())

Given this GREL expression:

value.parseXml().select("titleproper").toString()

I get this result:

<titleproper>
 "Intendencia de Veracruz"
</titleproper>

But, trying to strip away the tags, this expression:

value.parseXml().select("titleproper").xmlText().toString()

Results in error:

Error: xmlText failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function

No fair! Shouldn't xmlText() work just like htmlText(), resulting in just what's inside the tags?

Advice appreciated,

Mark

Hi Mark,

select() returns an array, so the fix is simple - just index the first element of the array returned, ie

value.parseXml().select("titleproper")[0].xmlText()

The .toString() is unnecessary since you're already being returned a string.

Tom

p.s. it's easier for people to help you if you include all the data necessary to reproduce your example.
pps I suppose your first example could be made to return '[ "Intendencia de Veracruz"]" but I suspect that, on balance, it would make more users unhappier.

1 Like

Thanks, Tom,

"select() returns an array". I missed this in the documentation, but sure enough there it is, right on the screen. Thanks for pointing out.

Everything working and all is well!

Much appreciated,

Mark