123456789_123456789_123456789_123456789_123456789_

Exception: Nokogiri::XML::SyntaxError

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Nokogiri::SyntaxError
Defined in: lib/nokogiri/xml/syntax_error.rb,
ext/nokogiri/xml_syntax_error.c

Overview

This class provides information about ::Nokogiri::XML SyntaxErrors. These exceptions are typically stored on Document#errors.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.aggregate(errors)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 10

def aggregate(errors)
  return nil if errors.empty?
  return errors.first if errors.length == 1

  messages = ["Multiple errors encountered:"]
  errors.each do |error|
    messages << error.to_s
  end
  new(messages.join("\n"))
end

Instance Attribute Details

#code (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 23

attr_reader :code

#column (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 40

attr_reader :column

#domain (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 22

attr_reader :domain

#error?Boolean (readonly)

return true if this is an error

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 56

def error?
  level == 2
end

#fatal?Boolean (readonly)

return true if this error is fatal

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 62

def fatal?
  level == 3
end

#file (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 25

attr_reader :file

#int1 (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 39

attr_reader :int1

#level (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 24

attr_reader :level

#line (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 26

attr_reader :line

#none?Boolean (readonly)

return true if this is a non error

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 44

def none?
  level == 0
end

#path (readonly)

The XPath path of the node that caused the error when validating a Document.

This attribute will only be non-nil when the error is emitted by Schema#validate on Document objects. It will return nil for DOM parsing errors and for errors emitted during Schema validation of files.

#path is not supported on JRuby, where it will always return nil.

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 35

attr_reader :path

#str1 (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 36

attr_reader :str1

#str2 (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 37

attr_reader :str2

#str3 (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 38

attr_reader :str3

#warning?Boolean (readonly)

return true if this is a warning

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 50

def warning?
  level == 1
end

Instance Method Details

#level_to_s (private)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 75

def level_to_s
  case level
  when 3 then "FATAL"
  when 2 then "ERROR"
  when 1 then "WARNING"
  end
end

#location_to_s (private)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 87

def location_to_s
  return if nil_or_zero?(line) && nil_or_zero?(column)

  "#{line}:#{column}"
end

#nil_or_zero?(attribute) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 83

def nil_or_zero?(attribute)
  attribute.nil? || attribute.zero?
end

#to_s

[ GitHub ]

  
# File 'lib/nokogiri/xml/syntax_error.rb', line 66

def to_s
  message = super.chomp
  [location_to_s, level_to_s, message]
    .compact.join(": ")
    .force_encoding(message.encoding)
end