Before installing builder, we need to install Ruby and RubyGems (Standard Ruby Package manager) under the Rails framework. Download Ruby Windows Installer and double-click the Ruby185-21.exe file. After the Ruby Setup Wizard starts, click Next and accept the license agreement. Select the default part installation, including the RubyGems Package Manager. Specify a path to install Ruby (the default path is C:/ruby), and then click Next. Specify a start Directory folder and click the Install key to install Ruby and RubyGems. Next, install rails. Run the following command to install rails and rails satellite files from C:/ruby, which is the path that Ruby installs to.
c:/ruby>gem install rails --include-dependencies
Builder includes the RubyGems Package Manager. Run the following command to install Builder 2.0.0.
C:/ruby>gem install builder
This Builder::xmlmarkup class provides the methods discussed in table 1.
Method |
Describe |
Cdata! (text) |
Added a CDATA section. |
comment! (Comment_text) |
Add a comment. |
declare! (Inst, *args, &block) |
Add a declaration. parameter is specified as 0 or more parameters. |
instruct! (Directive_tag=:xml, attrs={}) |
Add a processing instruction. The attribute is specified with a hash table. |
New (options={}) |
Create an XML tag builder object with the next option: Target=>targetobject:indent=> Indentation:margin=>initial_indentation Declares the entry of a hash table. |
target! () |
Returns the target of the builder object. |
Table 1:builder::xmlmarkup Method
In order to create an XML file from the database, we also need to install the MySQL database. Download MySQL 5.0. Double-click Setup.exe to install MySQL, and then create a MySQL server instance.
Create an XML file from the database
In this section, we will create an XML file from the database table. To create an XML file from the database, we first create a rails application:
C:/ruby>rails databasexml
To specify a test database, modify the development mode settings in the App/config/database.yml file. The development mode settings for this MySQL database are listed in the following table.
development:
adapter: mysql
database: test
username: root
password: nil
host: localhost
We're going to use the ActiveRecord migration to create a database table. Create a migration script using the following Ruby command to create a model script:
C:\ruby\databasexml> ruby script/generate model catalog