class REXML::Element
Public Instance Methods
c14nxl(options = {})
click to toggle source
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.
@param [Hash{Symbol => Object}] options
From `Nokogiri::XML::Node#c14nxl`
# File lib/rdf/xsd/extensions.rb, line 177 def c14nxl(options = {}) # Add in-scope namespace definitions, unless supplied options[:namespaces] ||= self.namespaces element = options[:inplace] ? self : self.dup # Add in-scope namespace definitions options[:namespaces].each do |prefix, href| if prefix.to_s.empty? element.add_attribute("xmlns", href) unless element.attribute("xmlns") else element.add_attribute("xmlns:#{prefix}", href) unless element.attribute("xmlns:#{prefix}") end end # Add language element.add_attribute("xml:lang", options[:language].to_s) if options[:language] && element.attribute("lang", "http://www.w3.org/XML/1998/namespace").to_s.empty? && element.attribute("lang").to_s.empty? # Make sure it formats as open/close tags element.text = "" if element.text == nil && element.children.empty? # Recurse through children to ensure tags are set properly element.children.each {|c| c.c14nxl(:inplace => true, :namespaces => {}) if c.is_a?(REXML::Element)} element end