On Sep 5, 2011, at 1:28 AM, 7stud -- wrote:
> require 'rexml/document'
> 
> f = File.new("xml.xml")
> doc = REXML::Document.new(f)
> 
> REXML::XPath.each(doc, "//name") do |element|
>  puts "name: #{element.text}"
>  if sibling = element.next_element
>    puts sibling.text
>  else
>    puts "No <value> tag that is a sibling"
>  end
> 
>  puts "-" * 20
> end

For comparison, here's one way to write code with the similar functionality using Nokogiri, but ensuring that the <value> element is a sibling of the <name> element. Unlike the above code, the following allows any number of elements between the <name> and the <value>:
    require 'nokogiri'

    doc = Nokogiri::XML(IO.read("my.xml"))
    doc.search('name').each do |name|
      puts "name: #{name.text}"
      if value=name.at_xpath('following-sibling::value')
        puts value.text
      else
         puts "No <value> tag that is a sibling"
       end
       puts "-" * 20
    end

Output:
    name: Tove
    Tove's value is: 10
    --------------------
    name: Jani
    Jani's value is: 20
    --------------------
    name: No sibling
    No <value> tag that is a sibling
    --------------------

Again using this XML:
    <?xml version="1.0"?>
    <note>
      <name>Tove</name>
      <value>Tove's value is: 10</value>
      <garbage>xxxx</garbage>
  
      <to>Tove</to>
      <from>Jani</from>
      <heading>Reminder</heading>
      <body>Don't forget me this weekend!</body>

      <parent>
        <name>Jani</name>
        <value>Jani's value is: 20</value>
        <garbage>xxxx</garbage>
      </parent>

      <parent>
         <name>No sibling</name>
      </parent>
      <value>No sibling's value is: 30</value>
    </note>