class REXML::Formatters::Transitive
Transitive
格式化器写入一个 XML 文档,该文档的解析结果与源文档相同。这意味着不会插入额外的空白节点,并且保留文本节点内的空白。在这些约束条件下,文档会进行漂亮打印,空白会插入到元数据中以引入格式化。
请注意,这仅在原始 XML 尚未格式化时才有用。由于此格式化器不会更改空白节点,因此格式化已格式化的 XML 的结果将很奇怪。
公共类方法
new( indentation=2, ie_hack=false ) 点击切换源代码
# File rexml-3.4.0/lib/rexml/formatters/transitive.rb, line 16 def initialize( indentation=2, ie_hack=false ) @indentation = indentation @level = 0 @ie_hack = ie_hack end
受保护的实例方法
write_element( node, output ) 点击切换源代码
# File rexml-3.4.0/lib/rexml/formatters/transitive.rb, line 23 def write_element( node, output ) output << "<#{node.expanded_name}" node.attributes.each_attribute do |attr| output << " " attr.write( output ) end unless node.attributes.empty? output << "\n" output << ' '*@level if node.children.empty? output << " " if @ie_hack output << "/" else output << ">" # If compact and all children are text, and if the formatted output # is less than the specified width, then try to print everything on # one line @level += @indentation node.children.each { |child| write( child, output ) } @level -= @indentation output << "</#{node.expanded_name}" output << "\n" output << ' '*@level end output << ">" end
write_text( node, output ) 点击切换源代码
# File rexml-3.4.0/lib/rexml/formatters/transitive.rb, line 53 def write_text( node, output ) output << node.to_s() end