class Nokogiri::XML::Document
def collect_namespaces
{"xmlns:foo" => "baz"}
The hash returned will be something like:
Given this document:
*Example:* Duplicate prefixes
{"xmlns:foo"=>"bar", "xmlns"=>"default", "xmlns:hello"=>"world"}
This method will return:
Given this document:
*Example:* Basic usage
underlying XML library.
order (and which duplicate prefix "wins") may be dependent on the implementation of the
Note that this method does an xpath lookup for nodes with namespaces, and as a result the
⚠ This method will not handle duplicate namespace prefixes, since the return value is a hash.
hash.
Recursively get all namespaces from this node and its subtree and return them as a
collect_namespaces() → Hash
:call-seq:
def collect_namespaces xpath("//namespace::*").each_with_object({}) do |ns, hash| hash[["xmlns", ns.prefix].compact.join(":")] = ns.href if ns.prefix != "xml" end end