Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
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
Eclipse UserFriend
> 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
Eclipse UserFriend
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 Jul 20 12:57:32 EDT 2025

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

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

Back to the top