Skip to main content


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 13:52 Go to next message
Ralf Ebert is currently offline Ralf EbertFriend
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 14:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Escaping Strings in Xpand [message #531636 is a reply to message #531597] Wed, 05 May 2010 16:10 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
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, EMF, Eclipse IDE?
Go to: http://devhub.karakun.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 16:08 Go to previous messageGo to next message
Ralf Ebert is currently offline Ralf EbertFriend
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 16:19 Go to previous message
Ralf Ebert is currently offline Ralf EbertFriend
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: Thu Apr 25 02:22:44 GMT 2024

Powered by FUDForum. Page generated in 0.02837 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top