【发布时间】:2015-04-03 19:14:27
【问题描述】:
目标:
将 XML 转换为 ruby Hash ,包含所有节点和属性值
我尝试了什么:
xml =
'<test id="appears">
<comment id="doesnt appear">
it worked
</comment>
<comment>
see!
</comment>
<comment />
</test>'
hash = Hash.from_xml(xml)
现在我得到了这个哈希
#=>{"test"=>{"id"=>"appears", "comment"=>["it worked", "see!", nil]}}
注意第一个评论元素上的 id 属性没有出现。
如何解决这个问题?
【问题讨论】:
标签: ruby-on-rails ruby xml