Class: Canon::Xml::NamespaceHandler
- Inherits:
-
Object
- Object
- Canon::Xml::NamespaceHandler
- Defined in:
- lib/canon/xml/namespace_handler.rb
Overview
Namespace handler for C14N 1.1 Handles namespace declaration processing per spec
Instance Method Summary collapse
-
#initialize(encoder) ⇒ NamespaceHandler
constructor
A new instance of NamespaceHandler.
-
#process_namespaces(element, output, parent_element = nil) ⇒ Object
Process namespace axis of an element rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(encoder) ⇒ NamespaceHandler
Returns a new instance of NamespaceHandler.
8 9 10 |
# File 'lib/canon/xml/namespace_handler.rb', line 8 def initialize(encoder) @encoder = encoder end |
Instance Method Details
#process_namespaces(element, output, parent_element = nil) ⇒ Object
Process namespace axis of an element rubocop:disable Metrics/MethodLength
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/canon/xml/namespace_handler.rb', line 14 def process_namespaces(element, output, parent_element = nil) return unless element.in_node_set? namespaces = element.sorted_namespace_nodes.select(&:in_node_set?) # Check if we need to emit xmlns="" for empty default namespace if should_emit_empty_default_namespace?(element, namespaces, parent_element) output << ' xmlns=""' end # Process each namespace node namespaces.each do |ns| next if should_skip_namespace?(ns, element, parent_element) output << " " output << if ns.default_namespace? "xmlns" else "xmlns:#{ns.prefix}" end output << '="' output << @encoder.encode_attribute(ns.uri) output << '"' end end |