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