Class: Nokogiri::XML::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/xsd/extensions.rb

Instance Method Summary collapse

Instance Method Details

#c14nxl(options = {}) ⇒ Object

Canonicalize the Element. Return a new instance of this node which is canonicalized and marked as such.

Apply namespaces either passed as an option, or that are in scope.

Parameters:

  • options (Hash{Symbol => Object}) (defaults to: {})

    From Node#c14nxl



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rdf/xsd/extensions.rb', line 60

def c14nxl(options = {})
  options[:namespaces] ||= self.namespace_scopes.compact.inject({}) do |memo, ns|
    memo[ns.prefix] = ns.href.to_s
    memo
  end
  element = self.clone

  # Add in-scope namespace definitions
  options[:namespaces].each do |prefix, href|
    if prefix.to_s.empty?
      element.default_namespace = href unless element.namespace
    else
      element.add_namespace(prefix.to_s, href) unless element.namespaces[prefix.to_s]
    end
  end

  # Add language
  element["xml:lang"] = options[:language].to_s if
    options[:language] &&
    element.attribute_with_ns("lang", "http://www.w3.org/XML/1998/namespace").to_s.empty? &&
    element.attribute("lang").to_s.empty?

  element
end