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:
- Require 'builder'
-
- X = Builder: XmlMarkup. new (: target =>
$ Stdout,: indent => 1)
- # ": Target => $ stdout" parameter: indicates the output
Capacity will be written to the standard output Console
- # ": Indent => 1" parameter: the XML output format is reduced.
Enter a space character x. instruct! : Xml,
: Version => '1. 1',: encoding => 'gb2312'
- X. comment! "Book information"
-
- X. library ("shelf" => "Recent Acquisitions "){
- X. section ("name" => "ruby "){
- X. book ("isbn" => "0672310001 "){
- X. title "Programming Ruby"
- X. author "Yukihiro"
- X. description "Programming Ruby-
The Pragmatic Programmer's Guide"
- }
- }
- }
P x # print XML
Ruby creates XML output results:
- <? Xml version = "1.1" encoding = "gb2312"?>
- <! -- Book information -->
- <Library shelf = "Recent Acquisitions">
- <Section name = "ruby">
- <Book isbn = "0672310001">
- <Title> Programming Ruby </title>
- <Author> Yukihiro </author>
- <Description> Programming Ruby-
Pragmatic Programmer's Guide
- </Description>
- </Book>
- </Section>
- </Library>
- <Inspect/>
- # <IO: 0x2a06ae8>
The preceding section describes how to create XML in Ruby.