Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. require 'net/http'
  2. require 'xml/libxml'
  3. require 'rubygems'
  4. require_gem 'activerecord'
  5. # require 'db_address.rb'
  6.  
  7. ActiveRecord::Base.establish_connection(
  8. :adapter => "mysql",
  9. :username => "root",
  10. :host => "localhost",
  11. :password => "*****",
  12. :database => "mfinger_cms_db"
  13. )
  14.  
  15. class Address < ActiveRecord::Base
  16. self.inheritance_column = "address";
  17. end
  18. class Filename < ActiveRecord::Base
  19. self.inheritance_column = "filename";
  20. end
  21.  
  22. Address.find(:all).each do |address|
  23. # Get the address to the xml document
  24. http_address = Net::HTTP.new(address.address, 80)
  25. response = http_address.get(address.filename, nil)
  26.  
  27. if response.message == "OK"
  28. doc = XML::Document.file(response)
  29. root = doc.root
  30.  
  31. puts "Collected prices: #{root.name}"
  32.  
  33. elem3 = root.find('elem3').to_a.first
  34. puts "Elem3: #{elem3['attr']}"
  35.  
  36. doc.find('//root_node/foo/bar').each do |node|
  37. puts "Node path: #{node.path} \t Contents: #{node}"
  38. end
  39. end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement