Skip to content

Instantly share code, notes, and snippets.

@josephholsten
Last active December 16, 2015 16:28
Show Gist options
  • Save josephholsten/5462902 to your computer and use it in GitHub Desktop.
Save josephholsten/5462902 to your computer and use it in GitHub Desktop.
<products>
<product
product_id="227307351"
name="Sam Edelman Women's Ximon"
sku_number="227307351"
manufacturer_name="Sam Edelman"
part_number="00736701885362">
<category>
<primary>Apparel~~Footwear</primary>
<secondary></secondary>
</category>
<URL>
<product>http://affiliate.rakuten.com/link?id=g2*09Hrp7YA&amp;offerid=272843.227307351&amp;type=15&amp;murl=http%3A%2F%2Fshoes.store.buy.com%2Fp%2Fsam-edelman-women-s-ximon%2F227307351.html</product>
<productImage>http://images.rakuten.com/PI/0/250/227307351.jpg</productImage>
<buy></buy>
</URL>
<description>
<short>You ll be puddle-splashing chic in the Ximon rain boots from Sam Edelman.Rubber upper in a casual knee-high rain boot style with a round toeOuter side faux buttonsLogo detail, pull loop14 inch shaft height, 15 1/2 inch circumferenceFabric lining, removable cushioned insoleRubber traction outsole1 1/4 inch heel</short>
<long>You ll be puddle-splashing chic in the Ximon rain boots from Sam Edelman.Rubber upper in a casual knee-high rain boot style with a round toeOuter side faux buttonsLogo detail, pull loop14 inch shaft height, 15 1/2 inch circumferenceFabric lining, removable cushioned insoleRubber traction outsole1 1/4 inch heel</long>
</description>
<discount currency="USD">
<amount>0.00</amount>
<type>amount</type>
</discount>
<price currency="USD">
<sale begin_date="" end_date="">84.55</sale>
<retail>84.55</retail>
</price>
<brand>Sam Edelman</brand>
<shipping>
<cost currency="USD">
<amount>0.00</amount>
<currency>USD</currency>
</cost>
<information></information>
<availability>yes</availability>
</shipping>
<keywords></keywords>
<upc>00736701885362</upc>
<m1></m1>
<pixel>http://ad.linksynergy.com/fs-bin/show?id=g2*09Hrp7YA&amp;bids=272843.227307351&amp;type=15&amp;subid=0</pixel>
</product>
</products>
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
class Product < Struct.new(:id, :name, :short_description, :long_description)
def valid?
id and name and short_description and long_description
end
end
def parse_products(file_name)
file = open(file_name)
products = []
doc = Nokogiri::XML(open('/Users/joseph/products.xml'))
doc.xpath('//product').each do |product_elem|
id = product_elem['product_id']
name = product_elem['name']
short_description = product_elem.xpath('description/short').text
long_description = product_elem.xpath('description/long').text
product = Product.new(id, name, short_description, long_description)
products << product if product.valid?
end
file.close
return products
end
products = parse_products('/Users/joseph/products.xml')
puts products
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment