Easily implement Ruby to create XML

Source: Internet
Author: User

The use of the Ruby language can help us implement many functions. For example, this article will introduce you to the implementation methods for creating XML in Ruby, which is one of them.

  • Ruby module Win32API calls win32API directly
  • How to call win32ole IN Ruby
  • Ruby basic code Experience Sharing
  • Summary of several common Ruby core concepts
  • Ruby experience in configuring Mysql DBI

Environment Configuration:

Install ruby first and then builder

Builder Installation Method: gem install builder

Example code for creating xml in Ruby:

  1. Require 'builder'
  3. X = Builder: XmlMarkup. new (: target =>
    $ Stdout,: indent => 1)
  4. # ": Target => $ stdout" parameter: indicates the output
    Capacity will be written to the standard output Console
  5. # ": Indent => 1" parameter: the XML output format is reduced.
    Enter a space character x. instruct! : Xml,
    : Version => '1. 1',: encoding => 'gb2312'
  6. X. comment! "Book information"
  8. X. library ("shelf" => "Recent Acquisitions "){
  9. X. section ("name" => "ruby "){
  10. X. book ("isbn" => "0672310001 "){
  11. X. title "Programming Ruby"
  12. X. author "Yukihiro"
  13. X. description "Programming Ruby-
    The Pragmatic Programmer's Guide"
  14. }
  15. }
  16. }

P x # print XML

Ruby creates XML output results:

  1. <? Xml version = "1.1" encoding = "gb2312"?>
  2. <! -- Book information -->
  3. <Library shelf = "Recent Acquisitions">
  4. <Section name = "ruby">
  5. <Book isbn = "0672310001">
  6. <Title> Programming Ruby </title>
  7. <Author> Yukihiro </author>
  8. <Description> Programming Ruby-
    Pragmatic Programmer's Guide
  9. </Description>
  10. </Book>
  11. </Section>
  12. </Library>
  13. <Inspect/>
  14. # <IO: 0x2a06ae8>

The preceding section describes how to create XML in Ruby.

Related Article

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.