Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Escaping Strings in Xpand
Escaping Strings in Xpand [message #531597] Wed, 05 May 2010 09:52 Go to next message
Ralf Ebert is currently offline Ralf Ebert
Messages: 168
Registered: July 2009
Senior Member
What's the best approach for escaping Strings in Xpand templates? (for example for
generating XML you have to quote <, >, & characters). Defining a Xtend function to include
a JAVA function that does the job? If so, is there maybe a set of common String escaping
functions available somewhere or does everybody write these themself?

- Ralf | http://www.ralfebert.de/
Re: Escaping Strings in Xpand [message #531604 is a reply to message #531597] Wed, 05 May 2010 10:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5849
Registered: July 2009
Senior Member
Hello Ralf,

don't know of any built-in support in xpand. But StringEscapeUtils from Apache Commons Lang Supports such stuff.

~Christian
Re: Escaping Strings in Xpand [message #531636 is a reply to message #531597] Wed, 05 May 2010 12:10 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

Hi Ralf!

In Xpand you don't need to escape these characters. The only characters that need to be escaped are the guillemot brackets. Target XML code can be written as-is to the template.

~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Escaping Strings in Xpand [message #531639 is a reply to message #531604] Wed, 05 May 2010 12:08 Go to previous messageGo to next message
Ralf Ebert is currently offline Ralf Ebert
Messages: 168
Registered: July 2009
Senior Member
> don't know of any built-in support in xpand. But StringEscapeUtils from
> Apache Commons Lang Supports such stuff.

Thanks,

String xml(String xml) : JAVA
org.apache.commons.lang.StringEscapeUtils.escapeXml(java.lan g.String);

does the trick. I guess there isn't a way to tell xpand to apply such a function for every
value that goes into the output document? (writing «somevalue.xml()» for each and every
value is redundant and errorprone as it might be forgotten failing only one day where you
have a '&' char in the model data)

- Ralf | http://www.ralfebert.de/
Re: Escaping Strings in Xpand [message #531641 is a reply to message #531636] Wed, 05 May 2010 12:19 Go to previous message
Ralf Ebert is currently offline Ralf Ebert
Messages: 168
Registered: July 2009
Senior Member
Hi Karsten,

> In Xpand you don't need to escape these characters. The only characters
> that need to be escaped are the guillemot brackets. Target XML code can
> be written as-is to the template.

but if the model data contains a '&' character, this needs to be escaped to &amp; because
otherwise the XML document will be invalid, right?

- Ralf | http://www.ralfebert.de/
Previous Topic:extract the information of an association
Next Topic:[Xtend] Java parameter types
Goto Forum:
  


Current Time: Sun Apr 20 03:08:58 EDT 2014

Powered by FUDForum. Page generated in 0.04043 seconds