tag:blogger.com,1999:blog-8326467133854092913.post1997120068181716242..comments2023-06-02T08:41:00.844+01:00Comments on smartrics: Groovy for XML transformationsmartricshttp://www.blogger.com/profile/07295654362099098666noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8326467133854092913.post-7248180065635311282013-09-25T10:42:26.060+01:002013-09-25T10:42:26.060+01:00In Groovy you can also have templates as in Scala,...In Groovy you can also have templates as in Scala, see here: http://groovy.codehaus.org/Groovy+Templates<br /><br />In your code you are missing the key in the result XML.<br /><br />And it is only the half of the solution, see http://tatiyants.com/xml-transformation-performance-groovy-vs-xslt/Christian Lipphttps://www.blogger.com/profile/14588100767394522565noreply@blogger.comtag:blogger.com,1999:blog-8326467133854092913.post-32171985832436933202008-07-07T22:31:00.000+01:002008-07-07T22:31:00.000+01:00I promised myself to look at Scala a bit closer.@j...I promised myself to look at Scala a bit closer.<BR/><BR/>@jau: the approach shown in is similar to any other template technology (jsp, velocity, ...): they all suffer of the same painful problems: mixing xml syntax and native language, lack of IDE support. I find XmlSlurper+MarkupBuilder neater<BR/><BR/>@anonymous: Grails approach (which can be implemented in Groovy as well with few meta-programming) does't solve my problem. That is mapping <BR/><BR/>class Customer{<BR/> def id<BR/> def name<BR/> def surname<BR/>}<BR/><BR/>into<BR/><BR/><client><BR/> <key>...</key><BR/> <firstname>...</firstname><BR/> <secondname>...</secondname><BR/></client><BR/><BR/>Note the difference between the attribute name and the tag namesmartricshttps://www.blogger.com/profile/07295654362099098666noreply@blogger.comtag:blogger.com,1999:blog-8326467133854092913.post-30593788479946323982008-07-07T21:39:00.000+01:002008-07-07T21:39:00.000+01:00@jau -- okay you scala smartass -- in Grails (whic...@jau -- okay you scala smartass -- in Grails (which sits atop groovy):<BR/><BR/>p = new Person(key:blah, name:"bob", secondName:"smartass")<BR/><BR/>render p as XMLAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8326467133854092913.post-28402352372725771292008-07-07T15:40:00.000+01:002008-07-07T15:40:00.000+01:00And in Scala you do it&nb...And in Scala you do it like this<BR/><BR/><BR/><BR/>class Person(<BR/><BR/> val key: Int,<BR/><BR/> val name: String,<BR/><BR/> val secondName: String<BR/><BR/>)<BR/><BR/>{<BR/><BR/> def toXml = <BR/><BR/> <contact><BR/><BR/> <key> { key } </key><BR/><BR/> <firstname> {name } </firstname><BR/><BR/> <secondname> { secondName } </secondname><BR/><BR/> </contact><BR/><BR/>}mateusz.fiołkahttps://www.blogger.com/profile/09019915478026785150noreply@blogger.com