Class: XSD::XMLParser::OxParser

Inherits:
Parser show all
Defined in:
lib/xsd/xmlparser/oxparser.rb

Instance Attribute Summary

Attributes inherited from Parser

#charset

Instance Method Summary collapse

Methods inherited from Parser

add_factory, create_parser, factory, #initialize, #parse

Constructor Details

This class inherits a constructor from XSD::XMLParser::Parser

Instance Method Details

#do_parse(string_or_readable) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/xsd/xmlparser/oxparser.rb', line 15

def do_parse(string_or_readable)
  $stderr.puts "XSD::XMLParser::OxParser.do_parse" if $DEBUG
  begin
    require 'htmlentities' # Used to unescape html-escaped chars, if available
    @decoder = ::HTMLEntities.new(:expanded)
  rescue LoadError
    @decoder = nil
  end
  handler = OxDocHandler.new(self, @decoder)

  string = string_or_readable.respond_to?(:read) ? string_or_readable.read : StringIO.new(string_or_readable)
  if @decoder.nil?
    # Use the built-in conversion with Ox.
    ::Ox.sax_parse(handler, string, {:symbolize=> false, :convert_special=> true, :skip=> :skip_return} )
  else
    # Use HTMLEntities Decoder.  Leave the special-character conversion alone and let HTMLEntities decode it for us.
    ::Ox.sax_parse(handler, string, {})
  end
end