1 require 'rexml/formatters/pretty'
2 require 'rexml/formatters/transitive'
6 # The Transitive formatter writes an XML document that parses to an
7 # identical document as the source document. This means that no extra
8 # whitespace nodes are inserted, and whitespace within text nodes is
9 # preserved. Within these constraints, the document is pretty-printed,
10 # with whitespace inserted into the metadata to introduce formatting.
12 # Note that this is only useful if the original XML is not already
13 # formatted. Since this formatter does not alter whitespace nodes, the
14 # results of formatting already formatted XML will be odd.
15 class Transitive < Default
16 def initialize( indentation=2 )
17 @indentation = indentation
22 def write_element( node, output )
23 output << "<#{node.expanded_name}"
25 node.attributes.each_attribute do |attr|
28 end unless node.attributes.empty?
32 if node.children.empty?
36 # If compact and all children are text, and if the formatted output
37 # is less than the specified width, then try to print everything on
40 @level += @indentation
41 node.children.each { |child|
42 write( child, output )
44 @level -= @indentation
45 output << "</#{node.expanded_name}"
52 def write_text( node, output )