# frozen_string_literal: false
require "xml/encoding-ja"
# This error is legacy, so we just set it to the new one
Error = ::XMLParserError # :nodoc:
class REXMLLikeXMLParser < ::XML::Parser
include ::XML::Encoding_ja
def startElement(name, attrs)
@listener.tag_start(name, attrs)
def xmlDecl(version, encoding, standalone)
@listener.xmldecl(version, encoding, standalone == 1)
def processingInstruction(target, content)
@listener.instruction(target, content)
class XMLParserParser < BaseParser
parser = REXMLLikeXMLParser.new
parser.listener = @listener
rescue ::XML::Parser::Error => e
raise NotWellFormedError.new(parser.line){e.message}
class XMLParserListener < BaseListener
def xmldecl(version, encoding, standalone)
# Encoding is converted to UTF-8 when XMLParser parses XML.