diff -bur /usr/lib/ruby/1.8/rexml/document.rb ./document.rb --- /usr/lib/ruby/1.8/rexml/document.rb 2005-08-12 14:08:47.000000000 +0200 +++ ./document.rb 2006-07-15 12:58:19.000000000 +0200 @@ -158,12 +158,12 @@ # unable to parse proper XML, we have to provide a hack to generate XML # 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 ) + def write( output=$stdout, indent_level=-1, transitive=false, ie_hack=false ) 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 - if node.write( output, indent, transitive, ie_hack ) - output << "\n" unless indent<0 or node == @children[-1] + indent( output, indent_level ) if node.node_type == :element + if node.write( output, indent_level, transitive, ie_hack ) + output << "\n" unless indent_level<0 or node == @children[-1] end } end diff -bur /usr/lib/ruby/1.8/rexml/element.rb ./element.rb --- /usr/lib/ruby/1.8/rexml/element.rb 2005-08-12 14:08:47.000000000 +0200 +++ ./element.rb 2006-07-15 12:58:19.000000000 +0200 @@ -36,6 +36,8 @@ # If an Element, the object will be shallowly cloned; name, # attributes, and namespaces will be copied. Children will +not+ be # copied. + # If a Source, the source will be scanned and parsed for an Element, + # and all child elements will be recursively parsed as well. # parent:: # if supplied, must be a Parent, and will be used as # the parent of this object. @@ -221,7 +223,7 @@ # b.namespace("y") # -> '2' def namespace(prefix=nil) if prefix.nil? - prefix = prefix() + prefix = self.prefix() end if prefix == '' prefix = "xmlns" diff -bur /usr/lib/ruby/1.8/rexml/encoding.rb ./encoding.rb --- /usr/lib/ruby/1.8/rexml/encoding.rb 2005-12-09 15:31:47.000000000 +0100 +++ ./encoding.rb 2006-07-15 12:58:19.000000000 +0200 @@ -25,22 +25,28 @@ begin $VERBOSE = false return if defined? @encoding and enc == @encoding - if enc - raise ArgumentError, "Bad encoding name #{enc}" unless /\A[\w-]+\z/n =~ enc - @encoding = enc.upcase.untaint - else - @encoding = UTF_8 - end - err = nil - [@encoding, "ICONV"].each do |enc| + if enc and enc != UTF_8 + @encoding = enc.upcase begin - require File.join("rexml", "encodings", "#{enc}.rb") - return Encoding.apply(self, enc) + require 'rexml/encodings/ICONV.rb' + Encoding.apply(self, "ICONV") rescue LoadError, Exception => err + raise ArgumentError, "Bad encoding name #@encoding" unless @encoding =~ /^[\w-]+$/ + @encoding.untaint + enc_file = File.join( "rexml", "encodings", "#@encoding.rb" ) + begin + require enc_file + Encoding.apply(self, @encoding) + rescue LoadError + puts $!.message + raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv." end end - puts err.message - raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv." + else + @encoding = UTF_8 + require 'rexml/encodings/UTF-8.rb' + Encoding.apply(self, @encoding) + end ensure $VERBOSE = old_verbosity end diff -bur /usr/lib/ruby/1.8/rexml/functions.rb ./functions.rb --- /usr/lib/ruby/1.8/rexml/functions.rb 2005-08-12 14:08:47.000000000 +0200 +++ ./functions.rb 2006-07-15 12:58:19.000000000 +0200 @@ -339,8 +339,6 @@ end def Functions::sum( nodes ) - nodes = [nodes] unless nodes.kind_of? Array - nodes.inject(0) { |r,n| r += number(string(n)) } end def Functions::floor( number ) diff -bur /usr/lib/ruby/1.8/rexml/instruction.rb ./instruction.rb --- /usr/lib/ruby/1.8/rexml/instruction.rb 2005-08-12 14:08:47.000000000 +0200 +++ ./instruction.rb 2006-07-15 12:58:19.000000000 +0200 @@ -38,8 +38,8 @@ Instruction.new self end - def write writer, indent=-1, transitive=false, ie_hack=false - indent(writer, indent) + def write writer, indent_level=-1, transitive=false, ie_hack=false + indent(writer, indent_level) writer << START.sub(/\\/u, '') writer << @target writer << ' ' diff -bur /usr/lib/ruby/1.8/rexml/parsers/pullparser.rb ./parsers/pullparser.rb --- /usr/lib/ruby/1.8/rexml/parsers/pullparser.rb 2005-08-12 14:08:50.000000000 +0200 +++ ./parsers/pullparser.rb 2006-07-15 12:58:16.000000000 +0200 @@ -1,5 +1,3 @@ -require 'forwardable' - require 'rexml/parseexception' require 'rexml/parsers/baseparser' require 'rexml/xmltokens' @@ -27,17 +25,11 @@ # Nat Price gave me some good ideas for the API. class PullParser include XMLTokens - extend Forwardable - - def_delegators( :@parser, :has_next? ) - def_delegators( :@parser, :entity ) - def_delegators( :@parser, :empty? ) def initialize stream @entities = {} @listeners = nil @parser = BaseParser.new( stream ) - @my_stack = [] end def add_listener( listener ) @@ -52,18 +44,14 @@ end def peek depth=0 - if @my_stack.length <= depth - (depth - @my_stack.length + 1).times { - e = PullEvent.new(@parser.pull) - @my_stack.push(e) - } + PullEvent.new(@parser.peek(depth)) end - @my_stack[depth] + + def has_next? + @parser.has_next? end def pull - return @my_stack.shift if @my_stack.length > 0 - event = @parser.pull case event[0] when :entitydecl @@ -77,8 +65,17 @@ end def unshift token - @my_stack.unshift token + @parser.unshift token end + + def entity reference + @parser.entity( reference ) + end + + def empty? + @parser.empty? + end + end # A parsing event. The contents of the event are accessed as an +Array?, diff -bur /usr/lib/ruby/1.8/rexml/parsers/sax2parser.rb ./parsers/sax2parser.rb --- /usr/lib/ruby/1.8/rexml/parsers/sax2parser.rb 2005-08-12 14:08:50.000000000 +0200 +++ ./parsers/sax2parser.rb 2006-07-15 12:58:16.000000000 +0200 @@ -1,11 +1,9 @@ require 'rexml/parsers/baseparser' require 'rexml/parseexception' require 'rexml/namespace' -require 'rexml/text' module REXML module Parsers - # SAX2Parser class SAX2Parser def initialize source @parser = BaseParser.new(source) @@ -39,10 +37,6 @@ # :processing_instruction, :doctype, :attlistdecl, :elementdecl, # :entitydecl, :notationdecl, :cdata, :xmldecl, :comment # - # There is an additional symbol that can be listened for: :progress. - # This will be called for every event generated, passing in the current - # stream position. - # # Array contains regular expressions or strings which will be matched # against fully qualified element names. # @@ -167,7 +161,6 @@ :elementdecl, :cdata, :notationdecl, :xmldecl handle( *event ) end - handle( :progress, @parser.source.position ) end end diff -bur /usr/lib/ruby/1.8/rexml/rexml.rb ./rexml.rb --- /usr/lib/ruby/1.8/rexml/sax2listener.rb 2005-08-12 14:08:47.000000000 +0200 +++ ./sax2listener.rb 2006-07-15 12:58:19.000000000 +0200 @@ -90,7 +90,5 @@ # @p comment The content of the comment def comment comment end - def progress position - end end end diff -bur /usr/lib/ruby/1.8/rexml/source.rb ./source.rb --- /usr/lib/ruby/1.8/rexml/source.rb 2005-08-12 14:08:47.000000000 +0200 +++ ./source.rb 2006-07-15 12:58:19.000000000 +0200 @@ -98,10 +98,6 @@ @buffer == "" end - def position - @orig.index( @buffer ) - end - # @return the current line in the source def current_line lines = @orig.split @@ -198,10 +194,6 @@ super and ( @source.nil? || @source.eof? ) end - def position - @er_source.pos - end - # @return the current line in the source def current_line begin diff -bur /usr/lib/ruby/1.8/rexml/validation/validation.rb ./validation/validation.rb --- /usr/lib/ruby/1.8/rexml/validation/validation.rb 2005-08-12 14:08:52.000000000 +0200 +++ ./validation/validation.rb 2006-07-15 12:58:16.000000000 +0200 @@ -80,15 +80,16 @@ def initialize(event_type, event_arg=nil ) @event_type = event_type @event_arg = event_arg + @done = false end - attr_reader :event_type - attr_accessor :event_arg - def done? @done end + attr_reader :event_type + attr_accessor :event_arg + def single? return (@event_type != :start_element and @event_type != :start_attribute) end diff -bur /usr/lib/ruby/1.8/rexml/xmldecl.rb ./xmldecl.rb --- /usr/lib/ruby/1.8/rexml/xmldecl.rb 2005-08-12 14:08:47.000000000 +0200 +++ ./xmldecl.rb 2006-07-15 12:58:19.000000000 +0200 @@ -37,9 +37,9 @@ XMLDecl.new(self) end - def write writer, indent=-1, transitive=false, ie_hack=false + def write writer, indent_level=-1, transitive=false, ie_hack=false return nil unless @writethis or writer.kind_of? Output - indent( writer, indent ) + indent( writer, indent_level ) writer << START.sub(/\\/u, '') if writer.kind_of? Output writer << " #{content writer.encoding}" diff -bur /usr/lib/ruby/1.8/rexml/xpath_parser.rb ./xpath_parser.rb --- /usr/lib/ruby/1.8/rexml/xpath_parser.rb 2005-08-12 14:08:47.000000000 +0200 +++ ./xpath_parser.rb 2006-07-15 12:58:19.000000000 +0200 @@ -76,8 +76,6 @@ # Performs a depth-first (document order) XPath search, and returns the # first match. This is the fastest, lightest way to return a single result. - # - # FIXME: This method is incomplete! def first( path_stack, node ) #puts "#{depth}) Entering match( #{path.inspect}, #{tree.inspect} )" return nil if path.size == 0 @@ -125,6 +123,14 @@ r = expr( path_stack, nodeset ) #puts "MAIN EXPR => #{r.inspect}" r + + #while ( path_stack.size > 0 and nodeset.size > 0 ) + # #puts "MATCH: #{path_stack.inspect} '#{nodeset.collect{|n|n.class}.inspect}'" + # nodeset = expr( path_stack, nodeset ) + # #puts "NODESET: #{nodeset.inspect}" + # #puts "PATH_STACK: #{path_stack.inspect}" + #end + #nodeset end private @@ -379,10 +385,13 @@ return @variables[ var_name ] # :and, :or, :eq, :neq, :lt, :lteq, :gt, :gteq + # TODO: Special case for :or and :and -- not evaluate the right + # operand if the left alone determines result (i.e. is true for + # :or and false for :and). when :eq, :neq, :lt, :lteq, :gt, :gteq, :and, :or - left = expr( path_stack.shift, nodeset, context ) + left = expr( path_stack.shift, nodeset.dup, context ) #puts "LEFT => #{left.inspect} (#{left.class.name})" - right = expr( path_stack.shift, nodeset, context ) + right = expr( path_stack.shift, nodeset.dup, context ) #puts "RIGHT => #{right.inspect} (#{right.class.name})" res = equality_relational_compare( left, op, right ) #puts "RES => #{res.inspect}" diff -bur /usr/lib/ruby/1.8/rexml/xpath.rb ./xpath.rb --- /usr/lib/ruby/1.8/rexml/xpath.rb 2005-08-12 14:08:47.000000000 +0200 +++ ./xpath.rb 2006-07-15 12:58:19.000000000 +0200 @@ -20,6 +20,16 @@ # XPath.first( doc, "//b"} ) # XPath.first( node, "a/x:b", { "x"=>"http://doofus" } ) def XPath::first element, path=nil, namespaces={}, variables={} +=begin + raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.kind_of? Hash + raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of? Hash + parser = XPathParser.new + parser.namespaces = namespaces + parser.variables = variables + path = "*" unless path + parser.first( path, element ); +=end +#=begin raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.kind_of? Hash raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of? Hash parser = XPathParser.new @@ -28,6 +38,7 @@ path = "*" unless path element = [element] unless element.kind_of? Array parser.parse(path, element).flatten[0] +#=end end # Itterates over nodes that match the given path, calling the supplied