轻松实现Ruby创建XML
Ruby语言的运用可以帮助我们实现许多功能,比如这篇文章将为大家介绍的有关Ruby创建XML的相关实现方法,就是其中一种。
环境配置:
先安装ruby,再安装builder
builder安装方法: gem install builder
Ruby创建XML代码示例:
require 'builder' x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1) #":target =>$stdout"参数:指示输出内 容将被写向标准输出控制台 #":indent =>1"参数:XML输出形式将被缩 进一个空格字符x.instruct! :xml, :version =>'1.1',:encoding => 'gb2312' x.comment! "书本信息" 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 #打印XML
Ruby创建XML输出结果:
相关推荐
与卿画眉共浮生 2020-10-14
xiyang 2020-08-21
baijinswpu 2020-07-29
leonranri 2020-07-26
zhongliwen 2020-07-05
麋鹿麋鹿迷了路 2020-07-05
zengyu00 2020-07-05
XGQ 2020-07-04
CoderBoy 2020-06-28
whbing 2020-06-28
绝望的乐园 2020-06-27
wellfly 2020-06-26
菇星獨行 2020-06-25
草原孤狼 2020-06-25
坚持着执着 2020-06-16
wcqwcq 2020-06-14
yuanye0 2020-06-14
zhongliwen 2020-06-13
MrFuWen 2020-06-09