Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 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 Filenname < ActiveRecord::Base
  19. self.inheritance_column = "filename";
  20. end
  21.  
  22. Address.find(:all).each {|address| puts address.filename ; puts address.address }
  23.  
  24. # Get the address to the xml document
  25. http_address = Net::HTTP.new(address.address, 80)
  26. response = http_address.get(address.filename, nil)
  27.  
  28. if response.message == "OK"
  29. doc = XML::Document.file(response)
  30. root = doc.root
  31.  
  32. puts "Collected prices: #{root.name}"
  33.  
  34. elem3 = root.find('elem3').to_a.first
  35. puts "Elem3: #{elem3['attr']}"
  36.  
  37. doc.find('//root_node/foo/bar').each do |node|
  38. puts "Node path: #{node.path} \t Contents: #{node}"
  39. end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement