鉴于此,在grails动作中:
def xml = { rss(version: '2.0') { ... } } render(contentType: 'application/rss+xml', xml)
我看到了这个:
是否有一种简单的方法来打印XML?也许是渲染方法中内置的东西?
这是一种使用Groovy代码精简打印XML的简单方法:
def xml = "" def stringWriter = new StringWriter() def node = new XmlParser().parseText(xml); new XmlNodePrinter(new PrintWriter(stringWriter)).print(node) println stringWriter.toString() " + "
结果是: