Module: Moxml::SAX::NamespaceSplitter

Overview

Splits a flat attribute hash into regular attributes and namespace declarations.

Every adapter SAX bridge performs the same split: attributes whose names start with “xmlns” are namespace declarations, everything else is a regular attribute. This module provides a single implementation.

Instance Method Summary collapse

Instance Method Details

#split_attributes_and_namespaces(attributes) ⇒ Array(Hash, Hash)

Returns [regular_attrs, namespaces].

Parameters:

  • attributes (Hash, Array<Array>)

    attributes as a hash or array of pairs

Returns:

  • (Array(Hash, Hash))
    regular_attrs, namespaces


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/moxml/sax/namespace_splitter.rb', line 13

def split_attributes_and_namespaces(attributes)
  attrs = {}
  ns = {}

  each_attribute(attributes) do |name, value|
    name_s = name.to_s
    if name_s == "xmlns" || name_s.start_with?("xmlns:")
      prefix = name_s == "xmlns" ? nil : name_s.sub("xmlns:", "")
      ns[prefix] = value
    else
      attrs[name_s] = value
    end
  end

  [attrs, ns]
end