一目了然 rails html xml encode decode
程序员文章站
2022-05-19 23:24:42
...
1.9.2p320 :001 > require 'htmlentities' 1.9.2p320 :002 > c = HTMLEntities.new #=> #<HTMLEntities:0x007fef0a5b0468 @flavor="xhtml1"> 1.9.2p320 :003 > c.decode ">" #=> ">" 1.9.2p320 :004 > require 'cgi' # => false 1.9.2p320 :005 > CGI.unescapeHTML """ # => "\"" 1.9.2p320 :006 > helper.send :raw, "<" # => "<" 1.9.2p320 :007 > helper.send :raw, "</p>" # => "</p>" 1.9.2p320 :008 > helper.send :h, "</p>" # => "</p>"
xml稍微特别处理
require 'rubygems' require 'builder' content = <<eos SOME TEXT, GOES TO UPPERCASE other text <em>italics<em> xml = Builder::XmlMarkup.new xml.instruct! :xml, :version => '1.0' xml.book :id => 1.0 do xml.keyPic "keyPic1.jpg" xml.parts do xml.part :partId => "1", :name => "name" do xml.chapter :title => "title", :subtitle => "subtitle" do xml.text content end end end end #p xml #When running from the CLI (Cygwin), I get the following: <?xml version="1.0" encoding="UTF-8"?> <book id="1.0"> <keyPic>keyPic1.jpg</keyPic> <parts> <part partId="1" name="name"> <chapter title="title" subtitle="subtitle"> <text> SOME TEXT, GOES TO UPPERCASE other text <em>italics<em> </text> </chapter> </part> </parts> </book><inspect/> <text> SOME TEXT, GOES TO UPPERCASE other text <em>italics<em/> </text>
使用<< 操作符来添加不修改内容
xml.text do |t| t << content end
上一篇: VIM ctags setup ack
下一篇: 二货爆笑,表情都不够用