4 # Prints out the XML document with no formatting -- except if id_hack is
8 # If set to true, then inserts whitespace before the close of an empty
9 # tag, so that IE's bad XML parser doesn't choke.
10 def initialize( ie_hack=false )
14 # Writes the node to some output.
19 # A class implementing <TT><<</TT>. Pass in an Output object to
20 # change the output encoding.
21 def write( node, output )
25 if node.xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
26 output = Output.new( output, node.xml_decl.encoding )
28 write_document( node, output )
31 write_element( node, output )
33 when Declaration, ElementDecl, NotationDecl, ExternalEntity, Entity,
34 Attribute, AttlistDecl
35 node.write( output,-1 )
38 write_instruction( node, output )
44 write_comment( node, output )
47 write_cdata( node, output )
50 write_text( node, output )
53 raise Exception.new("XML FORMATTING ERROR")
59 def write_document( node, output )
60 node.children.each { |child| write( child, output ) }
63 def write_element( node, output )
64 output << "<#{node.expanded_name}"
66 node.attributes.each_attribute do |attr|
69 end unless node.attributes.empty?
71 if node.children.empty?
72 output << " " if @ie_hack
76 node.children.each { |child|
77 write( child, output )
79 output << "</#{node.expanded_name}"
84 def write_text( node, output )
88 def write_comment( node, output )
89 output << Comment::START
91 output << Comment::STOP
94 def write_cdata( node, output )
95 output << CData::START
100 def write_instruction( node, output )
101 output << Instruction::START.sub(/\\/u, '')
102 output << node.target
104 output << node.content
105 output << Instruction::STOP.sub(/\\/u, '')