Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'active_record'
- require 'builder'
- ActiveRecord::Base.establish_connection({
- :adapter => 'mysql',
- :database => 'gandc',
- :host => 'localhost',
- :username => 'noodl',
- :password => 'xxx'
- })
- class Book < ActiveRecord::Base
- set_primary_key :entryID
- has_many :components, :foreign_key => 'entryID'
- end
- class Component < ActiveRecord::Base
- set_primary_key :componentsID
- belongs_to :book, :foreign_key => 'entryID'
- end
- buffer = ''
- xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2)
- xml.instruct!
- Component.find(:all,
- :conditions => 'readyOmitDefer = 1',
- :limit => 10
- ).each do |comp|
- next unless comp.book
- xml.doc do
- [:entryID, :nameBinding, :ISBN, :ISBN10, :price].each do |attr|
- xml.field comp[attr], :name => attr
- end
- [:title, :author, :section, :originalTitle, :director,
- :language, :publisher, :subtitle, :description].each do |attr|
- xml.field comp.book[attr], :name => attr
- end
- end
- end
- puts buffer
Add Comment
Please, Sign In to add comment