Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions lib/rexml/xpath_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,30 +223,9 @@ def expr( path_stack, nodeset, context=nil )
nodesets
end
when :namespace
pre_defined_namespaces = {
"xml" => "http://www.w3.org/XML/1998/namespace",
}
nodeset = step(path_stack, any_type: :namespace) do
nodesets = []
nodeset.each do |node|
raw_node = node.raw_node
case raw_node.node_type
when :element
if @namespaces
nodesets << pre_defined_namespaces.merge(@namespaces)
else
nodesets << pre_defined_namespaces.merge(raw_node.namespaces)
end
when :attribute
if @namespaces
nodesets << pre_defined_namespaces.merge(@namespaces)
else
nodesets << pre_defined_namespaces.merge(raw_node.element.namespaces)
end
end
end
nodesets
end
warn 'Namespace axis is not supported in REXML::XPathParser', uplevel: 1
# TODO: We need to create NamespaceNode class to support this feature
nodeset = step(path_stack) { [] }
when :parent
nodeset = step(path_stack) do
nodesets = []
Expand Down
8 changes: 8 additions & 0 deletions test/xpath/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ def test_axe_parent
assert_equal 19, q.attributes["id"].to_i
end

def test_axe_namespace_no_error
$VERBOSE, verbose = nil, $VERBOSE
# Although namespace axis is not implemented yet, it should not raise NoMethodError
XPath.match(@@doc, "a/d/c/namespace::*")
ensure
$VERBOSE = verbose
end
Comment on lines +251 to +257

def test_abbreviated_attribute
assert_equal 'a', XPath::first( @@doc, "a[@id='1']" ).name
c = XPath::first( @@doc, "a/b/c[@id='4']" )
Expand Down
Loading