139
140
xml_decl().stand_alone?
142
# Write the XML tree out. This writes the entire XML document, including
143
# declarations and processing instructions.
145
# A controversial point is whether Document should always write the XML
146
# declaration (<?xml version='1.0'?>) whether or not one is given by the
147
# user (or source document). REXML does not write one if one was not
148
# specified, because it adds unneccessary bandwidth to applications such
143
# Write the XML tree out, optionally with indent. This writes out the
144
# entire XML document, including XML declarations, doctype declarations,
145
# and processing instructions (if any are given).
147
# A controversial point is whether Document should always write the XML
148
# declaration (<?xml version='1.0'?>) whether or not one is given by the
149
# user (or source document). REXML does not write one if one was not
150
# specified, because it adds unneccessary bandwidth to applications such
153
# See also the classes in the rexml/formatters package for the proper way
154
# to change the default formatting of XML output
152
157
# Document.new("<a><b/></a>").serialize
155
160
# tr = Transitive.new( output_string )
156
161
# Document.new("<a><b/></a>").serialize( tr )
159
# One of the rexml/formatters classes. If none is given, then the Pretty
160
# formatter will be used to dump the XML to the STDOUT.
161
def serialize( formatter = nil )
162
if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
163
output = Output.new( output, xml_decl.encoding )
166
formatter = REXML::Pretty.new( $stdout ) if (formatter.nil?)
168
@children.each { |node|
169
puts "node = #{node.inspect}"
170
indent( output, indent ) if node.node_type == :element
171
if node.write( output, indent, transitive, ie_hack )
172
output << "\n" unless indent<0 or node == @children[-1]
177
# Write the XML tree out, optionally with indent. This writes out the
178
# entire XML document, including XML declarations, doctype declarations,
179
# and processing instructions (if any are given).
181
# A controversial point is whether Document should always write the XML
182
# declaration (<?xml version='1.0'?>) whether or not one is given by the
183
# user (or source document). REXML does not write one if one was not
184
# specified, because it adds unneccessary bandwidth to applications such
187
# See also the classes in the rexml/formatters package for the proper way
188
# to change the default formatting of XML output
192
# output an object which supports '<< string'; this is where the
193
# document will be written.
195
# An integer. If -1, no indenting will be used; otherwise, the
196
# indentation will be twice this number of spaces, and children will be
197
# indented an additional amount. For a value of 3, every item will be
164
# output an object which supports '<< string'; this is where the
165
# document will be written.
167
# An integer. If -1, no indenting will be used; otherwise, the
168
# indentation will be twice this number of spaces, and children will be
169
# indented an additional amount. For a value of 3, every item will be
198
170
# indented 3 more levels, or 6 more spaces (2 * 3). Defaults to -1
200
# If transitive is true and indent is >= 0, then the output will be
201
# pretty-printed in such a way that the added whitespace does not affect
202
# the absolute *value* of the document -- that is, it leaves the value
203
# and number of Text nodes in the document unchanged.
205
# Internet Explorer is the worst piece of crap to have ever been
206
# written, with the possible exception of Windows itself. Since IE is
207
# unable to parse proper XML, we have to provide a hack to generate XML
208
# that IE's limited abilities can handle. This hack inserts a space
209
# before the /> on empty tags. Defaults to false
210
def write( output=$stdout, indent=-1, trans=false, ie_hack=false )
172
# If transitive is true and indent is >= 0, then the output will be
173
# pretty-printed in such a way that the added whitespace does not affect
174
# the absolute *value* of the document -- that is, it leaves the value
175
# and number of Text nodes in the document unchanged.
177
# Internet Explorer is the worst piece of crap to have ever been
178
# written, with the possible exception of Windows itself. Since IE is
179
# unable to parse proper XML, we have to provide a hack to generate XML
180
# that IE's limited abilities can handle. This hack inserts a space
181
# before the /> on empty tags. Defaults to false
182
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
211
183
if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
212
184
output = Output.new( output, xml_decl.encoding )
214
186
formatter = if indent > -1
216
188
REXML::Formatters::Transitive.new( indent, ie_hack )
218
190
REXML::Formatters::Pretty.new( indent, ie_hack )