Ruby 使用 XPath 搜索 XML 文档

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

xml = %{
<aquarium>
 <fish color="blue" size="small" />
 <fish color="orange" size="large">
   <fish color="green" size="small">
    <fish color="red" size="tiny" />
   </fish>
 </fish>
 <decoration type="castle" style="gaudy">
  <algae color="green" />
 </decoration>
</aquarium>}

require 'rexml/document'
doc = REXML::Document.new xml

p doc.elements['//fish']
# => <fish size='small' color='blue'/>