什么是在ruby中格式化xml字符串的最佳方法?
发布时间:2020-12-16 21:41:04 所属栏目:百科 来源:网络整理
导读:给出一个像这样的xml字符串: somenestedxmlvalue/xml/nested/some 什么是最好的选择(使用ruby)将其格式化为可读的东西: some nested xmlvalue/xml /nested/some 解决方法 require "rexml/document"include REXMLsource ='somenestedxmlvalue/xml/nested/so
给出一个像这样的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 ) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |