module SublimeDSL::Tools::XML

Tools to process XML.

Constants

FORBIDDEN_CHARS_MAP

Hash { 'forbidden character' => 'abbreviation' }.

FORBIDDEN_CHARS_RE

Regexp matching forbidden control characters.

Public Class Methods

load(string_or_io) click to toggle source

Returns a Nokogiri::XML::Document. Raises an exception if the text contains control characters forbidden in an XML document.

# File lib/sublime_dsl/tools/xml.rb, line 53
def self.load(string_or_io)
  text = string_or_io.respond_to?(:read) ? string_or_io.read : string_or_io
  if text =~ FORBIDDEN_CHARS_RE
    abbrev = FORBIDDEN_CHARS_MAP[$&]
    raise Error, "illegal control character in XML: #{$&.inspect} (#{abbrev})"
  end

  Nokogiri.XML(text, &:noblanks) # I hate this API
end