diff --git a/lib/oga/xml/document.rb b/lib/oga/xml/document.rb index 9a995ee..ae82630 100644 --- a/lib/oga/xml/document.rb +++ b/lib/oga/xml/document.rb @@ -89,23 +89,6 @@ module Oga end end - ## - # Returns the available namespaces. These namespaces are retrieved from - # the first element in the document. - # - # @see [Oga::XML::Element#available_namespaces] - # - def available_namespaces - children.each do |child| - # There's no guarantee that the first node is *always* an element - # node. - return child.available_namespaces if child.is_a?(Element) - end - - # In case the document is empty. - return {} - end - ## # Converts the document and its child nodes to XML. # diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 0ba6968..657df79 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -411,6 +411,8 @@ module Oga name = ast_node.children[1] context.each do |context_node| + next unless context_node.respond_to?(:available_namespaces) + context_node.available_namespaces.each do |_, namespace| if namespace.name == name or name == '*' nodes << namespace diff --git a/spec/oga/xml/document_spec.rb b/spec/oga/xml/document_spec.rb index e475b85..5c68e5c 100644 --- a/spec/oga/xml/document_spec.rb +++ b/spec/oga/xml/document_spec.rb @@ -71,20 +71,6 @@ describe Oga::XML::Document do end end - context '#available_namespaces' do - example 'return an empty Hash by default' do - described_class.new.available_namespaces.should be_empty - end - - example 'return the namespaces of the first element' do - namespace = Oga::XML::Namespace.new(:name => 'x') - element = Oga::XML::Element.new(:namespaces => {'x' => namespace}) - document = described_class.new(:children => [element]) - - document.available_namespaces['x'].should == namespace - end - end - context '#to_xml' do before do child = Oga::XML::Comment.new(:text => 'foo')