解决方法
Ruby核心REXML :: Document有漂亮的打印:
REXML::Document#write( output=$stdout,indent=-1,transitive=false,ie_hack=false )
indent: An integer. If -1,no
indenting will be used; otherwise,the
indentation will be twice this number
of spaces,and children will be
indented an additional amount. For a
value of 3,every item will be
indented 3 more levels,or 6 more
spaces (2 * 3). Defaults to -1
一个例子:
require "rexml/document" doc = REXML::Document.new "<a><b><c>TExt</c><d /></b><b><d/></b></a>" out = "" doc.write(out,1) puts out
生产:
<a> <b> <c> TExt </c> <d/> </b> <b> <d/> </b> </a>
编辑:Rails已经加载了REXML,因此您只需要生成新的文档,然后将漂亮的打印的XML写入一些字符串,然后将其嵌入到< pre>标签.