From e6636fe890ab7cf8f8f1b86ca54a3e10f98d43e6 Mon Sep 17 00:00:00 2001 From: ser Date: Tue, 9 Dec 2003 02:41:33 +0000 Subject: * Added the lower-case Shift-JIS files to the manifest. The upper-case ones should be deprecated, but I need a Shift-JIS encoded XML file to test against, first. * Added support for maintaining external entity occurances in DTDs * Deprecated the use of Document::DECLARATION. The new default declaration can be gotten with XMLDecl::default() * Refactored the encoding support code. It should be more robust now, and fixes a few bugs. * The XPath string() function now deals with Element nodes properly. * Serialization with Output objects now works as would be expected. * Various code cleanups, some reducing the number of warnings that Ruby 1.8.x produces with REXML. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rexml/document.rb | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'lib/rexml/document.rb') 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) -- cgit v1.2.3