cyber c. wrote in post #1064619:
> <dict>
>        <key>A</key>
>        <string>val1</string>
>        <key>B</key>
>        <string>val2</string>
>        <key>C</key>
>        <string>val3</string>
> </dict>
>
> I want to match name with key and extract value from string. Please help
> me.



You can use XPath again:

#-----------
require 'nokogiri'

xml = '
  <dict>
       <key>A</key>
       <string>val1</string>
       <key>B</key>
       <string>val2</string>
       <key>C</key>
       <string>val3</string>
  </dict>
'
document = Nokogiri::XML.parse xml

def get_string doc, key
   doc.xpath("//key[text()='#{key}']/following-sibling::*[1]/text()").text
end

puts get_string(document, 'B')
#-----------

By the way: I'm no XML expert, but relying on the order of the elements 
seems a rather "ugly" solution to me. I'd rather wrap the key string 
pairs in "entry" elements or so.

-- 
Posted via http://www.ruby-forum.com/.