Module: Moxml::SAX::NamespaceSplitter
- Included in:
- Adapter::Libxml::LibXMLSAXBridge, Adapter::Nokogiri::NokogiriSAXBridge, Adapter::OgaSAXBridge, Adapter::OxSAXBridge, Adapter::REXMLSAX2Bridge
- Defined in:
- lib/moxml/sax/namespace_splitter.rb
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
-
#split_attributes_and_namespaces(attributes) ⇒ Array(Hash, Hash)
[regular_attrs, namespaces].
Instance Method Details
#split_attributes_and_namespaces(attributes) ⇒ Array(Hash, Hash)
Returns [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 |