You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by BBuzzard <Bi...@bnsflogistics.com> on 2016/04/04 20:26:11 UTC

How do I bind XPath expression values to a template using Groovy

I have a small Groovy Class called "zzz". The purpose of this class is to
first demonstrate successfully passing a binding to the template engine
producing an output and then failing to bind to another template engine
using what appears to be the same set of bindings.

V1.template contains the base message that will be used with the bindings to
produce a final output. V1.properties contains an XPath expression that
should grab the value from an XML document and add it to the bindings.
T1.xml is the raw xml input file.

In the zzz Groovy Class I have hard coded the LastName in bindings1 and that
works. But, when I grab the lastName value from the XML file and add it to
bindings2 it fails. Both bindings appear to have exactly the same text, but
I have noticed that bindings1 is of type Bindings and binding2 is of type
Reference.

I assume that bindings2 being of Reference is what is causing my problem,
but I don't know how to cast or convert it to Binding. Please let me know
what I'm doing wrong.

I'm using Java 1.8 with groovy-all-2.3.10.jar

zzz.groovy <http://groovy.329449.n5.nabble.com/file/n5732187/zzz.groovy>  
T1.xml <http://groovy.329449.n5.nabble.com/file/n5732187/T1.xml>  
V1.properties
<http://groovy.329449.n5.nabble.com/file/n5732187/V1.properties>  
V1.template <http://groovy.329449.n5.nabble.com/file/n5732187/V1.template>  



--
View this message in context: http://groovy.329449.n5.nabble.com/How-do-I-bind-XPath-expression-values-to-a-template-using-Groovy-tp5732187.html
Sent from the Groovy Users mailing list archive at Nabble.com.

Re: How do I bind XPath expression values to a template using Groovy

Posted by BBuzzard <Bi...@bnsflogistics.com>.
I found way the second template would could execute.  The bindings must be in
the form of Map<String,Object>, but I was passing in a GString as the key
for the map.  Note: "$parameterName" is a GString.  After converting the key
to a String the second template executed correctly.



--
View this message in context: http://groovy.329449.n5.nabble.com/How-do-I-bind-XPath-expression-values-to-a-template-using-Groovy-tp5732187p5732195.html
Sent from the Groovy Users mailing list archive at Nabble.com.