09 - compressing whitespace in an xml document.rb
来自「O Reilly Ruby Cookbook source code」· RB 代码 · 共 22 行
RB
22 行
require 'rexml/document'text = %{<doc><a>Some whitespace</a> <b>Some more</b></doc>}REXML::Document.new(text, { :compress_whitespace => :all }).to_s# => "<doc><a>Some whitespace</a> <b>Some more</b></doc>"#---REXML::Document.new(text, { :compress_whitespace => %w{a} }).to_s# => "<doc><a>Some whitespace</a> <b>Some more</b></doc>"#---REXML::Document.new(text, { :respect_whitespace => %w{a} }).to_s# => "<doc><a>Some whitespace</a> <b>Some more</b></doc>"#---text = %{<doc><a>Some text</a>\n <b>Some more</b>\n\n}REXML::Document.new(text, { :compress_whitespace => :all }).to_s# => "<doc><a>Some text</a>\n <b>Some more</b>\n</doc>"REXML::Document.new(text, { :compress_whitespace => :all, :ignore_whitespace_nodes => :all }).to_s# => "<doc><a>Some text</a><b>Some more</b></doc>"#---
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?