rub*_*iii 6 ruby xml formatting
给出一个像这样的xml字符串:
<some><nested><xml>value</xml></nested></some>
Run Code Online (Sandbox Code Playgroud)
什么是最好的选择(使用ruby)将其格式化为可读的东西:
<some>
<nested>
<xml>value</xml>
</nested>
</some>
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
#write写入任何带<<(字符串)的东西,所以这也是有效的:
doc.write( $stdout, 2 )
doc.write( an_open_file, 2 )
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3227 次 |
| 最近记录: |