Write XML on the Rails app

Source: Internet
Author: User
Tags cdata hash processing instruction mysql database

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.