module OpenAgent::XMLHelpers

Constants

PP_XSL
PP_XSLT

Public Instance Methods

formatted_xml(xml, pretty_print=true) click to toggle source
# File lib/openagent/xml_helpers.rb, line 8
def formatted_xml(xml, pretty_print=true)
  pretty_print ? parse_well_formed_xml(xml) : xml
end
parse_well_formed_xml(xml) click to toggle source

If XML is well-formed, reformat it as a pretty XML document.

# File lib/openagent/xml_helpers.rb, line 17
def parse_well_formed_xml(xml)
  doc = Nokogiri::XML(xml){ |c| c.strict }
  pretty_xml(doc)
rescue Nokogiri::XML::SyntaxError
  xml
end
pretty_xml(doc) click to toggle source
# File lib/openagent/xml_helpers.rb, line 12
def pretty_xml(doc)
  PP_XSL.apply_to(doc).to_s
end