class Nokogiri::XML::Node

def namespaces


# "xmlns:in_scope"=>"http://example.com/in_scope"}
# "xmlns"=>"http://example.com/root",
# => {"xmlns:foo"=>"http://example.com/foo",
doc.at_xpath("//root:third", "root" => "http://example.com/root").namespaces
# "xmlns:in_scope"=>"http://example.com/in_scope"}
# => {"xmlns"=>"http://example.com/child",
doc.at_xpath("//child:second", "child" => "http://example.com/child").namespaces
# "xmlns:in_scope"=>"http://example.com/in_scope"}
# => {"xmlns"=>"http://example.com/root",
doc.at_xpath("//root:first", "root" => "http://example.com/root").namespaces
EOF





doc = Nokogiri::XML(<<~EOF)

*Example:*

namespace prefix, and the hash value for each key is the namespace URI.
Hash containing all the namespaces on this node and its ancestors. The hash keys are the
[Returns]

See also #namespace_scopes

The default namespace for this node will be included with key "xmlns".

such as "xmlns:prefix", not just the prefix.
Note that the keys in this hash XML attributes that would be used to define this namespace,

Fetch all the namespaces on this node and its ancestors.

namespaces() → Hash
:call-seq:
def namespaces
  namespace_scopes.each_with_object({}) do |ns, hash|
    prefix = ns.prefix
    key = prefix ? "xmlns:#{prefix}" : "xmlns"
    hash[key] = ns.href
  end
end