<?xml version="1.0" encoding="UTF-8"?>
<requests>
<request id="77" payee="Georgia">
<claim claimNbr="44" adjuster="Ginnie"/>
</request>
</requests>
require 'nokogiri' reader = Nokogiri::XML::Reader( File.open('requests.xml') ) reader.each do |node| puts node.name attributes = node.attributes.inspect puts attributes end
request {"id"=>"77", "payee"=>"Georgia"} #text {} claim {"claimNbr"=>"44", "adjuster"=>"Ginnie"} #text {} request {"id"=>"77", "payee"=>"Georgia"} #text {}
A workaround has been found. The following is printed by the alternative code below:
77 Georgia
require 'nokogiri' doc = Nokogiri::XML(open('requests.xml')) puts doc.xpath("//requests/request").attribute("id") puts doc.xpath("//requests/request").attribute("payee")