diff options
Diffstat (limited to 'lib/rexml/document.rb')
-rw-r--r-- | lib/rexml/document.rb | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/rexml/document.rb b/lib/rexml/document.rb index 8617f904e6..1eefaea92a 100644 --- a/lib/rexml/document.rb +++ b/lib/rexml/document.rb @@ -19,7 +19,9 @@ module REXML class Document < Element # A convenient default XML declaration. If you want an XML declaration, # the easiest way to add one is mydoc << Document::DECLARATION - DECLARATION = XMLDecl.new( "1.0", "UTF-8" ) + # +DEPRECATED+ + # Use: mydoc << XMLDecl.default + DECLARATION = XMLDecl.default # Constructor # @param source if supplied, must be a Document, String, or IO. @@ -102,30 +104,27 @@ module REXML # @return the XMLDecl of this document; if no XMLDecl has been # set, the default declaration is returned. def xml_decl - rv = @children.find { |item| item.kind_of? XMLDecl } - rv = DECLARATION if rv.nil? - rv + rv = @children[0] + return rv if rv.kind_of? XMLDecl + rv = @children.unshift(XMLDecl.default)[0] end # @return the XMLDecl version of this document as a String. # If no XMLDecl has been set, returns the default version. def version - decl = xml_decl() - decl.nil? ? XMLDecl.DEFAULT_VERSION : decl.version + xml_decl().version end # @return the XMLDecl encoding of this document as a String. # If no XMLDecl has been set, returns the default encoding. def encoding - decl = xml_decl() - decl.nil? or decl.encoding.nil? ? XMLDecl.DEFAULT_ENCODING : decl.encoding + xml_decl().encoding end # @return the XMLDecl standalone value of this document as a String. # If no XMLDecl has been set, returns the default setting. def stand_alone? - decl = xml_decl() - decl.nil? ? XMLDecl.DEFAULT_STANDALONE : decl.stand_alone? + xml_decl().stand_alone? end # Write the XML tree out, optionally with indent. This writes out the @@ -154,8 +153,9 @@ module REXML # that IE's limited abilities can handle. This hack inserts a space # before the /> on empty tags. Defaults to false def write( output=$stdout, indent=-1, transitive=false, ie_hack=false ) - output = Output.new( output, xml_decl.encoding ) if xml_decl.encoding != "UTF-8" + output = Output.new( output, xml_decl.encoding ) if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output) @children.each { |node| + indent( output, indent) if node.node_type == :element node.write( output, indent, transitive, ie_hack ) output << "\n" unless indent<0 or node == @children[-1] } @@ -193,7 +193,7 @@ module REXML build_context.add( Text.new( event[1], true, nil, true ) ) unless ( - event[1].strip.size == 0 and + event[1].strip.size==0 and build_context.ignore_whitespace_nodes ) end @@ -218,6 +218,9 @@ module REXML when :attlistdecl n = AttlistDecl.new( event[1..-1] ) build_context.add( n ) + when :externalentity + n = ExternalEntity.new( event[1] ) + build_context.add( n ) when :elementdecl n = ElementDecl.new( event[1] ) build_context.add(n) |