Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse XML document in Ruby

Tags:

xml

ruby

I'm using REXML library.

<foo>
  <baa>value<baa>
<foo>

I want to get value belongs to baa.

How to code it ?

like image 888
freddiefujiwara Avatar asked Jul 01 '09 05:07

freddiefujiwara


1 Answers

try this


require 'rexml/document'

doc = REXML::Document.new File.new('mydoc.xml')

doc.elements('*/foo/baa') { |element| puts element.get_text }

I prefer Nokogiri and Hpricot gems myself. You can try them if you want.

like image 89
Rishav Rastogi Avatar answered Oct 19 '22 17:10

Rishav Rastogi