From: Robert Klemme Date: 2012-06-15T15:57:01+09:00 Subject: Re: Parsing xml dict files On Thu, Jun 14, 2012 at 7:53 PM, cyber c. wrote: > > Hi, > > I know that i can use "Nokogiri" to parse xml files and search for > results. > How do we deal with xml dict files where you have a [key,string] pairs > associated. > > Sample file > > > >       A >       val1 >       B >       val2 >       C >       val3 > 08:55:20 Temp$ ./xml.rb A -> val1 B -> val2 C -> val3 08:55:36 Temp$ cat -n xml.rb 1 #!/opt/bin/ruby19 2 3 require 'nokogiri' 4 5 dom = Nokogiri.XML < 8 A 9 val1 10 B 11 val2 12 C 13 val3 14 15 16 XML 17 18 dom.xpath('//key').each do |key| 19 printf "%s -> %s\n", key.text(), key.at_xpath('following-sibling::string/text()').text() 20 end Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/