summaryrefslogtreecommitdiff
path: root/lib/rexml/xpath_parser.rb
diff options
context:
space:
mode:
authorser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-08 02:03:44 +0000
committerser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-08 02:03:44 +0000
commitec847fad4e0c1b96c6cf91e7ff14ef0820f7ccc3 (patch)
tree5e6ceeb9a9fcb13bfba05d7eef0b49d398f78a76 /lib/rexml/xpath_parser.rb
parentb2a8ca6dd61358ed72c3d4f5f61767052c9b4d27 (diff)
Merged changes into HEAD from REXML 3.1.5.
The list of bug fixes/enhancements is at: http://www.germane-software.com/projects/rexml/query?status=closed&milestone=3.1.5 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/xpath_parser.rb')
-rw-r--r--lib/rexml/xpath_parser.rb40
1 files changed, 26 insertions, 14 deletions
diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb
index 98ed70cc10..a813236e10 100644
--- a/lib/rexml/xpath_parser.rb
+++ b/lib/rexml/xpath_parser.rb
@@ -10,9 +10,13 @@ class Object
end
end
class Symbol
- def dclone
- self
- end
+ def dclone ; self ; end
+end
+class Fixnum
+ def dclone ; self ; end
+end
+class Float
+ def dclone ; self ; end
end
class Array
def dclone
@@ -34,7 +38,7 @@ module REXML
def initialize( )
@parser = REXML::Parsers::XPathParser.new
- @namespaces = {}
+ @namespaces = nil
@variables = {}
end
@@ -130,6 +134,21 @@ module REXML
private
+ # Returns a String namespace for a node, given a prefix
+ # The rules are:
+ #
+ # 1. Use the supplied namespace mapping first.
+ # 2. If no mapping was supplied, use the context node to look up the namespace
+ def get_namespace( node, prefix )
+ if @namespaces
+ return @namespaces[prefix] || ''
+ else
+ return node.namespace( prefix ) if node.node_type == :element
+ return ''
+ end
+ end
+
+
# Expr takes a stack of path elements and a set of nodes (either a Parent
# or an Array and returns an Array of matching nodes
ALL = [ :attribute, :element, :text, :processing_instruction, :comment ]
@@ -152,12 +171,9 @@ module REXML
#puts "IN QNAME"
prefix = path_stack.shift
name = path_stack.shift
- default_ns = @namespaces[prefix]
- default_ns = default_ns ? default_ns : ''
nodeset.delete_if do |node|
- ns = default_ns
# FIXME: This DOUBLES the time XPath searches take
- ns = node.namespace( prefix ) if node.node_type == :element and ns == ''
+ ns = get_namespace( node, prefix )
#puts "NS = #{ns.inspect}"
#puts "node.node_type == :element => #{node.node_type == :element}"
if node.node_type == :element
@@ -209,11 +225,7 @@ module REXML
node_types = ELEMENTS
when :literal
- literal = path_stack.shift
- if literal =~ /^\d+(\.\d+)?$/
- return ($1 ? literal.to_f : literal.to_i)
- end
- return literal
+ return path_stack.shift
when :attribute
new_nodeset = []
@@ -224,7 +236,7 @@ module REXML
for element in nodeset
if element.node_type == :element
#puts element.name
- attr = element.attribute( name, @namespaces[prefix] )
+ attr = element.attribute( name, get_namespace(element, prefix) )
new_nodeset << attr if attr
end
end