Class: Canon::Formatters::XmlFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/formatters/xml_formatter.rb

Class Method Summary collapse

Class Method Details

.format(xml, pretty: true, indent: 2) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/canon/formatters/xml_formatter.rb', line 12

def self.format(xml, pretty: true, indent: 2)
  if pretty
    Canon::PrettyPrinter::Xml.new(indent: indent).format(xml)
  else
    Canon::Xml::C14n.canonicalize(xml, with_comments: false)
  end
end

.parse(xml) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/canon/formatters/xml_formatter.rb', line 20

def self.parse(xml)
  Canon::Validators::XmlValidator.validate!(xml)
  if XmlBackend.nokogiri?
    Nokogiri::XML(xml)
  else
    XmlParsing.parse(xml)
  end
end