| Class | REXML::XPathParser |
| In: |
|
| Parent: | Object |
You don’t want to use this class. Really. Use XPath, which is a wrapper for this class. Believe me. You don’t want to poke around in here. There is strange, dark magic at work in this code. Beware. Go back! Go back while you still can!
Methods
Included Modules
Constants
Public Class methods
35: def initialize( ) 36: @parser = REXML::Parsers::XPathParser.new 37: @namespaces = {} 38: @variables = {} 39: end
Public Instance methods
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!
81: def first( path_stack, node ) 82: #puts "#{depth}) Entering match( #{path.inspect}, #{tree.inspect} )" 83: return nil if path.size == 0 84: 85: case path[0] 86: when :document 87: # do nothing 88: return first( path[1..-1], node ) 89: when :child 90: for c in node.children 91: #puts "#{depth}) CHILD checking #{name(c)}" 92: r = first( path[1..-1], c ) 93: #puts "#{depth}) RETURNING #{r.inspect}" if r 94: return r if r 95: end 96: when :qname 97: name = path[2] 98: #puts "#{depth}) QNAME #{name(tree)} == #{name} (path => #{path.size})" 99: if node.name == name 100: #puts "#{depth}) RETURNING #{tree.inspect}" if path.size == 3 101: return node if path.size == 3 102: return first( path[3..-1], node ) 103: else 104: return nil 105: end 106: when :descendant_or_self 107: r = first( path[1..-1], node ) 108: return r if r 109: for c in node.children 110: r = first( path, c ) 111: return r if r 112: end 113: when :node 114: return first( path[1..-1], node ) 115: when :any 116: return first( path[1..-1], node ) 117: end 118: return nil 119: end
59: def get_first path, nodeset 60: #puts "#"*40 61: path_stack = @parser.parse( path ) 62: #puts "PARSE: #{path} => #{path_stack.inspect}" 63: #puts "PARSE: nodeset = #{nodeset.inspect}" 64: first( path_stack, nodeset ) 65: end
122: def match( path_stack, nodeset ) 123: #puts "MATCH: path_stack = #{path_stack.inspect}" 124: #puts "MATCH: nodeset = #{nodeset.inspect}" 125: r = expr( path_stack, nodeset ) 126: #puts "MAIN EXPR => #{r.inspect}" 127: r 128: end
41: def namespaces=( namespaces={} ) 42: Functions::namespace_context = namespaces 43: @namespaces = namespaces 44: end
51: def parse path, nodeset 52: #puts "#"*40 53: path_stack = @parser.parse( path ) 54: #puts "PARSE: #{path} => #{path_stack.inspect}" 55: #puts "PARSE: nodeset = #{nodeset.inspect}" 56: match( path_stack, nodeset ) 57: end
67: def predicate path, nodeset 68: path_stack = @parser.parse( path ) 69: expr( path_stack, nodeset ) 70: end