1
下面的代碼返回一個錯誤,我不知道爲什麼:未定義的方法錯誤
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:爲 「假」 未定義的方法`physicallyPresentInRegistrationCountry」:字符串(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
看起來就是這樣。謝謝!將接受答案。 – Arjun 2012-03-23 02:51:03
@ user666730不客氣,歡迎來到Stack Overflow – 2012-03-23 02:52:10