Class: XMLCleaner::NamespaceCorrectingErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
public/app/lib/xml_cleaner.rb

Overview

An error handler that rewrites the underlying XML to resolve missing namespace errors.

Defined Under Namespace

Classes: RetryParse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ NamespaceCorrectingErrorHandler

Returns a new instance of NamespaceCorrectingErrorHandler.



60
61
62
# File 'public/app/lib/xml_cleaner.rb', line 60

def initialize(file_path)
  @file_path = file_path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*) ⇒ Object



79
80
81
# File 'public/app/lib/xml_cleaner.rb', line 79

def method_missing(*)
  # All other errors are ignored
end

Instance Method Details

#fatal_error(exception) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'public/app/lib/xml_cleaner.rb', line 64

def fatal_error(exception)
  if exception.getMessage =~ /The prefix "(.*)" for .*? "(\1:.*?)".* is not bound./ &&
     exception.line_number &&
     exception.column_number

    # Caused by an undefined namespace such as `ns2:href`.  We can correct these
    element_to_fix = $2
    remove_namespace_prefix!(element_to_fix, exception.line_number, exception.column_number)

    raise RetryParse.new
  else
    raise exception
  end
end