Class: REXML::Element
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/extensions.rb
Instance Method Summary collapse
-
#c14nxl(options = {}) ⇒ Object
Canonicalize the Element.
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.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/extensions.rb', line 177 def c14nxl( = {}) # Add in-scope namespace definitions, unless supplied [:namespaces] ||= self.namespaces element = [:inplace] ? self : self.dup # Add in-scope namespace definitions [: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", [:language].to_s) if [: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 |