Module: Lutaml::Xml::BlankNamespaceHandler

Defined in:
lib/lutaml/xml/blank_namespace_handler.rb

Overview

BlankNamespaceHandler - Handle W3C xmlns="" blank namespace compliance

Extracts logic for determining when to add xmlns="" declaration based on W3C XML Namespaces 1.0 §6.2 semantics.

Examples:

Usage in adapter

if BlankNamespaceHandler.needs_xmlns_blank?(mapping: mapping, options: options)
  attributes["xmlns"] = ""
end

Class Method Summary collapse

Class Method Details

.needs_xmlns_blank?(mapping:, options:) ⇒ Boolean

Determine if element needs xmlns="" declaration

Per W3C XML Namespaces 1.0 §6.2, xmlns="" explicitly declares the blank namespace. This is ONLY for elements with explicit namespace: :blank declaration. Elements with nil namespace (unqualified) silently inherit parent's namespace.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lutaml/xml/blank_namespace_handler.rb', line 24

def self.needs_xmlns_blank?(mapping:, options:)
  parent_uses_default_ns = options[:parent_uses_default_ns]
  parent_element_form_default = options[:parent_element_form_default]

  # Case 1: Element has EXPLICIT :blank namespace
  # Must explicitly declare xmlns="" to remove parent's default namespace
  if mapping.namespace_class == :blank && parent_uses_default_ns
    return true
  end

  # Case 2: W3C compliance for unqualified children
  # When parent has default namespace but element_form_default is NOT set
  # (defaults to :unqualified per W3C), children need xmlns="" to explicitly
  # opt out of inheritance.
  # If parent has element_form_default :qualified, children inherit by default (no xmlns="").
  # If parent has element_form_default :unqualified, children should have NO xmlns at all.
  if mapping.namespace_class.nil? &&
      parent_uses_default_ns &&
      parent_element_form_default.nil?
    return true
  end

  false
end