Created
December 11, 2011 21:58
-
-
Save anonymous/1463002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rexml/document" | |
require "rubygems" | |
require "builder" | |
customers = [] | |
items = [] | |
File.open("orders.xml", "r") do |file| | |
doc = REXML::Document.new(file) | |
doc.root.elements.each do |order| | |
order.elements.each do |element| | |
if element.name == "address" | |
customers << element.elements["name"].text | |
customers << element.elements["street"].text | |
customers << element.elements["city"].text | |
customers << element.elements["state"].text | |
customers << element.elements["zip"].text | |
customers << element.elements["country"].text | |
elsif element.name == "items" | |
element.elements["item"].each do |item| | |
items << item | |
end | |
end | |
end | |
end | |
end | |
p customers | |
p items | |
Výpis: | |
["Ellen Adams", "123 Maple street", "Mill Valley", "CA", "10999", "USA", "Tai Yee", "8 Oak Avenue", "Old Town", "PA", "95819", "USA", "Cristian Osorio", "456 Main street", "Buffalo", "NY", "98112", "USA", "Cristian Osorio", "456 Main street", "Buffalo", "NY", "98112", "USA", "Jessica Arnold", "4055 Madison Ave", "Seattle", "WA", "98112", "USA", "Jessica Arnold", "4055 Madison Ave", "Buffalo", "NY", "98112", "USA"] | |
["\n ", <name> ... </>, "\n ", <quantity> ... </>, "\n ", <price> ... </>, "\n ", "\n ", <name> ... </>, "\n ", <quantity> ... </>, "\n ", <price> ... </>, "\n ", "\n ", <name> ... </>, "\n ", <quantity> ... </>, "\n ", <price> ... </>, "\n "] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment