I call the method "read" and only return one item from xml file
the method "read" return:
9 3 max date 5
and should return all items from xml
how do I get the whole xml from the method read?
Sorry for my english
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
No comments:
Post a Comment