mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* Fixed the inheritance bug in the pull parser that James Britt found.
* Indentation changes, and changed some exceptions to runtime exceptions. * Backed out the patch that changed the versions * Wasn't including Text class. * Fixes issue:25 (Trac) * Fixes ticket:3 (Issue38 in Roundup.) * Numerous fixes in the XPath interpreter correcting, among other things, ordering bugs and some incorrect behavior. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1b12d598f8
commit
69e5c7d297
15 changed files with 792 additions and 786 deletions
|
@ -101,20 +101,20 @@ module REXML
|
||||||
end
|
end
|
||||||
|
|
||||||
@unnormalized = nil
|
@unnormalized = nil
|
||||||
@value = @normalized = Text::normalize( @value, doctype )
|
@normalized = Text::normalize( @value, doctype )
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the UNNORMALIZED value of this attribute. That is, entities
|
# Returns the UNNORMALIZED value of this attribute. That is, entities
|
||||||
# have been expanded to their values
|
# have been expanded to their values
|
||||||
def value
|
def value
|
||||||
@unnormalized if @unnormalized
|
return @unnormalized if @unnormalized
|
||||||
doctype = nil
|
doctype = nil
|
||||||
if @element
|
if @element
|
||||||
doc = @element.document
|
doc = @element.document
|
||||||
doctype = doc.doctype if doc
|
doctype = doc.doctype if doc
|
||||||
end
|
end
|
||||||
@normalized = nil
|
@normalized = nil
|
||||||
@value = @unnormalized = Text::unnormalize( @value, doctype )
|
@unnormalized = Text::unnormalize( @value, doctype )
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a copy of this attribute
|
# Returns a copy of this attribute
|
||||||
|
|
|
@ -158,12 +158,12 @@ module REXML
|
||||||
# unable to parse proper XML, we have to provide a hack to generate XML
|
# 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
|
# that IE's limited abilities can handle. This hack inserts a space
|
||||||
# before the /> on empty tags. Defaults to false
|
# before the /> on empty tags. Defaults to false
|
||||||
def write( output=$stdout, indent_level=-1, transitive=false, ie_hack=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.kind_of?(Output)
|
output = Output.new( output, xml_decl.encoding ) if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
|
||||||
@children.each { |node|
|
@children.each { |node|
|
||||||
indent( output, indent_level ) if node.node_type == :element
|
indent( output, indent ) if node.node_type == :element
|
||||||
if node.write( output, indent_level, transitive, ie_hack )
|
if node.write( output, indent, transitive, ie_hack )
|
||||||
output << "\n" unless indent_level<0 or node == @children[-1]
|
output << "\n" unless indent<0 or node == @children[-1]
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,8 +36,6 @@ module REXML
|
||||||
# If an Element, the object will be shallowly cloned; name,
|
# If an Element, the object will be shallowly cloned; name,
|
||||||
# attributes, and namespaces will be copied. Children will +not+ be
|
# attributes, and namespaces will be copied. Children will +not+ be
|
||||||
# copied.
|
# 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::
|
# parent::
|
||||||
# if supplied, must be a Parent, and will be used as
|
# if supplied, must be a Parent, and will be used as
|
||||||
# the parent of this object.
|
# the parent of this object.
|
||||||
|
@ -223,7 +221,7 @@ module REXML
|
||||||
# b.namespace("y") # -> '2'
|
# b.namespace("y") # -> '2'
|
||||||
def namespace(prefix=nil)
|
def namespace(prefix=nil)
|
||||||
if prefix.nil?
|
if prefix.nil?
|
||||||
prefix = self.prefix()
|
prefix = prefix()
|
||||||
end
|
end
|
||||||
if prefix == ''
|
if prefix == ''
|
||||||
prefix = "xmlns"
|
prefix = "xmlns"
|
||||||
|
|
|
@ -339,6 +339,8 @@ module REXML
|
||||||
end
|
end
|
||||||
|
|
||||||
def Functions::sum( nodes )
|
def Functions::sum( nodes )
|
||||||
|
nodes = [nodes] unless nodes.kind_of? Array
|
||||||
|
nodes.inject(0) { |r,n| r += number(string(n)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def Functions::floor( number )
|
def Functions::floor( number )
|
||||||
|
|
|
@ -38,8 +38,8 @@ module REXML
|
||||||
Instruction.new self
|
Instruction.new self
|
||||||
end
|
end
|
||||||
|
|
||||||
def write writer, indent_level=-1, transitive=false, ie_hack=false
|
def write writer, indent=-1, transitive=false, ie_hack=false
|
||||||
indent(writer, indent_level)
|
indent(writer, indent)
|
||||||
writer << START.sub(/\\/u, '')
|
writer << START.sub(/\\/u, '')
|
||||||
writer << @target
|
writer << @target
|
||||||
writer << ' '
|
writer << ' '
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'forwardable'
|
||||||
|
|
||||||
require 'rexml/parseexception'
|
require 'rexml/parseexception'
|
||||||
require 'rexml/parsers/baseparser'
|
require 'rexml/parsers/baseparser'
|
||||||
require 'rexml/xmltokens'
|
require 'rexml/xmltokens'
|
||||||
|
@ -25,11 +27,17 @@ module REXML
|
||||||
# Nat Price gave me some good ideas for the API.
|
# Nat Price gave me some good ideas for the API.
|
||||||
class PullParser
|
class PullParser
|
||||||
include XMLTokens
|
include XMLTokens
|
||||||
|
extend Forwardable
|
||||||
|
|
||||||
|
def_delegators( :@parser, :has_next? )
|
||||||
|
def_delegators( :@parser, :entity )
|
||||||
|
def_delegators( :@parser, :empty? )
|
||||||
|
|
||||||
def initialize stream
|
def initialize stream
|
||||||
@entities = {}
|
@entities = {}
|
||||||
@listeners = nil
|
@listeners = nil
|
||||||
@parser = BaseParser.new( stream )
|
@parser = BaseParser.new( stream )
|
||||||
|
@my_stack = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_listener( listener )
|
def add_listener( listener )
|
||||||
|
@ -44,14 +52,18 @@ module REXML
|
||||||
end
|
end
|
||||||
|
|
||||||
def peek depth=0
|
def peek depth=0
|
||||||
PullEvent.new(@parser.peek(depth))
|
if @my_stack.length <= depth
|
||||||
|
(depth - @my_stack.length + 1).times {
|
||||||
|
e = PullEvent.new(@parser.pull)
|
||||||
|
@my_stack.push(e)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
@my_stack[depth]
|
||||||
def has_next?
|
|
||||||
@parser.has_next?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def pull
|
def pull
|
||||||
|
return @my_stack.shift if @my_stack.length > 0
|
||||||
|
|
||||||
event = @parser.pull
|
event = @parser.pull
|
||||||
case event[0]
|
case event[0]
|
||||||
when :entitydecl
|
when :entitydecl
|
||||||
|
@ -65,17 +77,8 @@ module REXML
|
||||||
end
|
end
|
||||||
|
|
||||||
def unshift token
|
def unshift token
|
||||||
@parser.unshift token
|
@my_stack.unshift token
|
||||||
end
|
end
|
||||||
|
|
||||||
def entity reference
|
|
||||||
@parser.entity( reference )
|
|
||||||
end
|
|
||||||
|
|
||||||
def empty?
|
|
||||||
@parser.empty?
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# A parsing event. The contents of the event are accessed as an +Array?,
|
# A parsing event. The contents of the event are accessed as an +Array?,
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
require 'rexml/parsers/baseparser'
|
require 'rexml/parsers/baseparser'
|
||||||
require 'rexml/parseexception'
|
require 'rexml/parseexception'
|
||||||
require 'rexml/namespace'
|
require 'rexml/namespace'
|
||||||
|
require 'rexml/text'
|
||||||
|
|
||||||
module REXML
|
module REXML
|
||||||
module Parsers
|
module Parsers
|
||||||
|
# SAX2Parser
|
||||||
class SAX2Parser
|
class SAX2Parser
|
||||||
def initialize source
|
def initialize source
|
||||||
@parser = BaseParser.new(source)
|
@parser = BaseParser.new(source)
|
||||||
|
@ -37,6 +39,10 @@ module REXML
|
||||||
# :processing_instruction, :doctype, :attlistdecl, :elementdecl,
|
# :processing_instruction, :doctype, :attlistdecl, :elementdecl,
|
||||||
# :entitydecl, :notationdecl, :cdata, :xmldecl, :comment
|
# :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
|
# Array contains regular expressions or strings which will be matched
|
||||||
# against fully qualified element names.
|
# against fully qualified element names.
|
||||||
#
|
#
|
||||||
|
@ -161,6 +167,7 @@ module REXML
|
||||||
:elementdecl, :cdata, :notationdecl, :xmldecl
|
:elementdecl, :cdata, :notationdecl, :xmldecl
|
||||||
handle( *event )
|
handle( *event )
|
||||||
end
|
end
|
||||||
|
handle( :progress, @parser.source.position )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
# Main page:: http://www.germane-software.com/software/rexml
|
# Main page:: http://www.germane-software.com/software/rexml
|
||||||
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
|
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
|
||||||
# Version:: 3.1.3
|
# Version:: 3.1.3
|
||||||
# Date:: +2005/138
|
# Date:: 2005/224
|
||||||
#
|
#
|
||||||
# This API documentation can be downloaded from the REXML home page, or can
|
# This API documentation can be downloaded from the REXML home page, or can
|
||||||
# be accessed online[http://www.germane-software.com/software/rexml_doc]
|
# be accessed online[http://www.germane-software.com/software/rexml_doc]
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
# or can be accessed
|
# or can be accessed
|
||||||
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
|
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
|
||||||
module REXML
|
module REXML
|
||||||
Copyright = "Copyright © 2001-2005 Sean Russell <ser@germane-software.com>"
|
Copyright = "Copyright © 2001, 2002, 2003, 2004 Sean Russell <ser@germane-software.com>"
|
||||||
Date = "+2005/138"
|
Date = "2005/224"
|
||||||
Version = "3.1.3"
|
Version = "3.1.3"
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,5 +90,7 @@ module REXML
|
||||||
# @p comment The content of the comment
|
# @p comment The content of the comment
|
||||||
def comment comment
|
def comment comment
|
||||||
end
|
end
|
||||||
|
def progress position
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,6 +98,10 @@ module REXML
|
||||||
@buffer == ""
|
@buffer == ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def position
|
||||||
|
@orig.index( @buffer )
|
||||||
|
end
|
||||||
|
|
||||||
# @return the current line in the source
|
# @return the current line in the source
|
||||||
def current_line
|
def current_line
|
||||||
lines = @orig.split
|
lines = @orig.split
|
||||||
|
@ -194,6 +198,10 @@ module REXML
|
||||||
super and ( @source.nil? || @source.eof? )
|
super and ( @source.nil? || @source.eof? )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def position
|
||||||
|
@er_source.pos
|
||||||
|
end
|
||||||
|
|
||||||
# @return the current line in the source
|
# @return the current line in the source
|
||||||
def current_line
|
def current_line
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -82,10 +82,13 @@ module REXML
|
||||||
@event_arg = event_arg
|
@event_arg = event_arg
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :done?
|
|
||||||
attr_reader :event_type
|
attr_reader :event_type
|
||||||
attr_accessor :event_arg
|
attr_accessor :event_arg
|
||||||
|
|
||||||
|
def done?
|
||||||
|
@done
|
||||||
|
end
|
||||||
|
|
||||||
def single?
|
def single?
|
||||||
return (@event_type != :start_element and @event_type != :start_attribute)
|
return (@event_type != :start_element and @event_type != :start_attribute)
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,9 +37,9 @@ module REXML
|
||||||
XMLDecl.new(self)
|
XMLDecl.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def write writer, indent_level=-1, transitive=false, ie_hack=false
|
def write writer, indent=-1, transitive=false, ie_hack=false
|
||||||
return nil unless @writethis or writer.kind_of? Output
|
return nil unless @writethis or writer.kind_of? Output
|
||||||
indent( writer, indent_level )
|
indent( writer, indent )
|
||||||
writer << START.sub(/\\/u, '')
|
writer << START.sub(/\\/u, '')
|
||||||
if writer.kind_of? Output
|
if writer.kind_of? Output
|
||||||
writer << " #{content writer.encoding}"
|
writer << " #{content writer.encoding}"
|
||||||
|
|
|
@ -20,16 +20,6 @@ module REXML
|
||||||
# XPath.first( doc, "//b"} )
|
# XPath.first( doc, "//b"} )
|
||||||
# XPath.first( node, "a/x:b", { "x"=>"http://doofus" } )
|
# XPath.first( node, "a/x:b", { "x"=>"http://doofus" } )
|
||||||
def XPath::first element, path=nil, namespaces={}, variables={}
|
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 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
|
raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of? Hash
|
||||||
parser = XPathParser.new
|
parser = XPathParser.new
|
||||||
|
@ -38,7 +28,6 @@ module REXML
|
||||||
path = "*" unless path
|
path = "*" unless path
|
||||||
element = [element] unless element.kind_of? Array
|
element = [element] unless element.kind_of? Array
|
||||||
parser.parse(path, element).flatten[0]
|
parser.parse(path, element).flatten[0]
|
||||||
#=end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Itterates over nodes that match the given path, calling the supplied
|
# Itterates over nodes that match the given path, calling the supplied
|
||||||
|
|
|
@ -76,6 +76,8 @@ module REXML
|
||||||
|
|
||||||
# Performs a depth-first (document order) XPath search, and returns the
|
# Performs a depth-first (document order) XPath search, and returns the
|
||||||
# first match. This is the fastest, lightest way to return a single result.
|
# first match. This is the fastest, lightest way to return a single result.
|
||||||
|
#
|
||||||
|
# FIXME: This method is incomplete!
|
||||||
def first( path_stack, node )
|
def first( path_stack, node )
|
||||||
#puts "#{depth}) Entering match( #{path.inspect}, #{tree.inspect} )"
|
#puts "#{depth}) Entering match( #{path.inspect}, #{tree.inspect} )"
|
||||||
return nil if path.size == 0
|
return nil if path.size == 0
|
||||||
|
@ -123,14 +125,6 @@ module REXML
|
||||||
r = expr( path_stack, nodeset )
|
r = expr( path_stack, nodeset )
|
||||||
#puts "MAIN EXPR => #{r.inspect}"
|
#puts "MAIN EXPR => #{r.inspect}"
|
||||||
r
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue