Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 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. class Parser
  23. def search
  24. Address.find(:all).each do |address|
  25. # Get the address to the xml document
  26. http_address = Net::HTTP.new(address.address, 80)
  27. response = http_address.get(address.filename, nil)
  28.  
  29. # file = File.new("#{RAILS_ROOT}/vendor/parsers/data_dump.txt")
  30. # data_dump = file.gets(nil)
  31.  
  32. if response.message == "OK"
  33. test = parse_xml(response)
  34. end
  35. end
  36.  
  37. def parse_xml(html)
  38. doc = XML::Document.file(response)
  39. root = doc.root
  40.  
  41. puts "Collected prices: #{root.name}"
  42.  
  43. elem3 = root.find('elem3').to_a.first
  44. puts "Elem3: #{elem3['attr']}"
  45.  
  46. doc.find('//root_node/foo/bar').each do |node|
  47. puts "Node path: #{node.path} \t Contents: #{node}"
  48. end
  49. end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement