0
我調用該方法「閱讀」,只有從XML文件中返回一個項目引入nokogiri返回一個項目
方法「讀」迴歸:
9
3
max
date
5
,而應返回的所有項目從xml
如何從方法讀取得到整個xml?
require 'nokogiri'
require 'open-uri'
def create
var = 0
while var < 10
builder = Nokogiri::XML::Builder.new do
item {
data var
port '3'
length 'max'
date 'date'
limit '5'
}
var += 1
end
end
return Nokogiri::XML(builder.to_xml).root.to_xml
end
def read
doc = Nokogiri::XML(create)
doc.xpath('//item').each do |item|
data = item.at_xpath('./data').content
port = item.at_xpath('./port').content
length = item.at_xpath('./length').content
date = item.at_xpath('./date').content
limit = item.at_xpath('./limit').content
puts data
puts port
puts length
puts date
puts limit
end
end
read