=begin
Ruby中 使用Xml Markup 轻松的对XML文档操作,
项目地址:http://builder.rubyforge.org/
使用之前我们需要安装Builder xml markup
前置条件
您的机器已经安装了RubyGems(Windows平台的一步安装文件RubyRubyInstaller.exe(我机器是RubyInstaller-1.9.3-p194),安装完毕系统就自带RubyGems)
Windows系统:
在命令行输入:
gem install builder 即可
×××××××××××××××××××××××
安装信息:
C:\Users\jj92>gem install builder
Fetching: builder-3.2.2.gem (100%)
Successfully installed builder-3.2.2
1 gem installed
Installing ri documentation for builder-3.2.2...
Installing RDoc documentation for builder-3.2.2...
=end
require 'builder'
x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1)
x.comment! "Book info"
x.library("shelf" => "Recent Acquisitions") do
x.section("name" => "ruby")do
x.book("isbn" => "") do
x.title "Programming Ruby"
x.author "Yukihiro "
x.description "Programming Ruby - The Pragmatic Programmer's Guide"
end
end
end
p x #打印XML
=begin resuolt:
<!-- Book info -->
<library shelf="Recent Acquisitions">
<section name="ruby">
<book isbn="">
<title>Programming Ruby</title>
<author>Yukihiro </author>
<description>Programming Ruby - The Pragmatic Programmer's Guide</description>
</book>
</section>
</library>
<inspect/>
#<IO:0x170a360>
=end