Class: Canon::Formatters::XmlFormatter
- Inherits:
-
Object
- Object
- Canon::Formatters::XmlFormatter
- Defined in:
- lib/canon/formatters/xml_formatter.rb
Overview
XML formatter using Canonical XML 1.1 or pretty printing
Class Method Summary collapse
-
.format(xml, pretty: true, indent: 2) ⇒ String
Format XML with pretty printing by default.
-
.parse(xml) ⇒ Nokogiri::XML::Document
Parse XML into a Nokogiri document.
Class Method Details
.format(xml, pretty: true, indent: 2) ⇒ String
Format XML with pretty printing by default
17 18 19 20 21 22 23 |
# File 'lib/canon/formatters/xml_formatter.rb', line 17 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) ⇒ Nokogiri::XML::Document
Parse XML into a Nokogiri document
28 29 30 31 32 |
# File 'lib/canon/formatters/xml_formatter.rb', line 28 def self.parse(xml) # Validate before parsing Canon::Validators::XmlValidator.validate!(xml) Nokogiri::XML(xml) end |