给定一个像这样的 xml 字符串:
<some><nested><xml>value</xml></nested></some>
什么是最好的选择(使用 ruby)将它格式化成可读的东西:
<some>
<nested>
<xml>value</xml>
</nested>
</some>
最佳答案
require "rexml/document"
include REXML
source ='<some><nested><xml>value</xml></nested></some>'
doc = Document.new( source )
doc.write( targetstr = "", 2 ) #indents with 2 spaces
puts targetstr
#write 写入任何需要
doc.write( $stdout, 2 )
doc.write( an_open_file, 2 )
https://stackoverflow.com/questions/2465911/