From: "Jan E." Date: 2012-06-15T05:49:17+09:00 Subject: Re: Parsing xml dict files cyber c. wrote in post #1064619: > > A > val1 > B > val2 > C > val3 > > > I want to match name with key and extract value from string. Please help > me. You can use XPath again: #----------- require 'nokogiri' xml = ' A val1 B val2 C val3 ' 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/.