Exception: Nokogiri::XML::SyntaxError

Inherits:
SyntaxError
  • Object
show all
Defined in:
lib/nokogiri/xml/syntax_error.rb,
ext/nokogiri/xml_syntax_error.c

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#columnObject (readonly)

Returns the value of attribute column.



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

def column
  @column
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#int1Object (readonly)

Returns the value of attribute int1.



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

def int1
  @int1
end

#levelObject (readonly)

Returns the value of attribute level.



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

def level
  @level
end

#lineObject (readonly)

Returns the value of attribute line.



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

def line
  @line
end

#pathObject (readonly)

The XPath path of the node that caused the error when validating a ‘Nokogiri::XML::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`.



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

def path
  @path
end

#str1Object (readonly)

Returns the value of attribute str1.



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

def str1
  @str1
end

#str2Object (readonly)

Returns the value of attribute str2.



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

def str2
  @str2
end

#str3Object (readonly)

Returns the value of attribute str3.



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

def str3
  @str3
end

Class Method Details

.aggregate(errors) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# 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 Method Details

#error?Boolean

return true if this is an error

Returns:

  • (Boolean)


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

def error?
  level == 2
end

#fatal?Boolean

return true if this error is fatal

Returns:

  • (Boolean)


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

def fatal?
  level == 3
end

#none?Boolean

return true if this is a non error

Returns:

  • (Boolean)


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

def none?
  level == 0
end

#to_sObject



66
67
68
69
70
71
# 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

#warning?Boolean

return true if this is a warning

Returns:

  • (Boolean)


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

def warning?
  level == 1
end