The following code returns an error and I dont know why:
require "rexml/document"
include REXML
file = File.new("test.xml")
doc = REXML::Document.new file
class Registration
attr_accessor :number, :jurisdiction, :physicallyPresentInRegistrationCountry
end
def constructRegistration(item, typeOfMerchant)
reg = Registration.new
element = item.elements[typeOfMerchant + "PhysicallyPresentInRegistrationCountry"]
if element != nil then
reg,physicallyPresentInRegistrationCountry = element.text
else
reg.physicallyPresentInRegistrationCountry = nil
end
return reg
end
XPath.each(doc, "//transactionAuditRecordList/item") { |item|
reg = constructRegistration(item, "seller")
puts reg.physicallyPresentInRegistrationCountry
}
rexml.rb:26: undefined method `physicallyPresentInRegistrationCountry’ for “false”:String (NoMethodError)
from /usr/lib/ruby/1.8/rexml/xpath.rb:53:in `each'
from /usr/lib/ruby/1.8/rexml/xpath.rb:53:in `each'
from rexml.rb:24
Looks like a stray comma instead of a dot:
This has the effect of doing a multi-assignment to two vars
regandphysicallyPresentInRegistrationCountrybut only one expression on the right side of=means that