Exception: Nokogiri::XML::SyntaxError

Inherits:
SyntaxError
  • Object
show all
Defined in:
lib/nokogiri/xml/syntax_error.rb,
lib/nokogiri/ffi/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.

Direct Known Subclasses

XPath::SyntaxError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ SyntaxError

Returns a new instance of SyntaxError.



7
8
9
# File 'lib/nokogiri/xml/syntax_error.rb', line 7

def initialize message
  self.message = message
end

Instance Attribute Details

#cstructObject

Returns the value of attribute cstruct.



6
7
8
# File 'lib/nokogiri/ffi/xml/syntax_error.rb', line 6

def cstruct
  @cstruct
end

Class Method Details

.error_array_pusher(array) ⇒ Object



71
72
73
74
75
# File 'lib/nokogiri/ffi/xml/syntax_error.rb', line 71

def error_array_pusher(array)
  Proc.new do |_ignored_, error|
    array << wrap(error) if array
  end
end

.wrap(error_ptr) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/nokogiri/ffi/xml/syntax_error.rb', line 77

def wrap(error_ptr)
  error_struct = LibXML::XmlSyntaxError.allocate
  LibXML.xmlCopyError(error_ptr, error_struct)
  error_cstruct = LibXML::XmlSyntaxError.new(error_struct)
  error = self.allocate # will generate XML::XPath::SyntaxError or XML::SyntaxError
  error.cstruct = error_cstruct
  error
end

Instance Method Details

#codeObject

Get the error code



133
134
135
# File 'ext/nokogiri/xml_syntax_error.c', line 133

def code
  cstruct[:code]
end

#columnObject Also known as: int2

Column number or 0 if not available



24
25
26
# File 'ext/nokogiri/xml_syntax_error.c', line 24

def column
  cstruct[:int2]
end

#domainObject

Get the part of the library that raised this exception



146
147
148
# File 'ext/nokogiri/xml_syntax_error.c', line 146

def domain
  cstruct[:domain]
end

#error?Boolean

return true if this is an error

Returns:

  • (Boolean)


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

def error?
  level == 2
end

#fatal?Boolean

return true if this error is fatal

Returns:

  • (Boolean)


31
32
33
# File 'lib/nokogiri/xml/syntax_error.rb', line 31

def fatal?
  level == 3
end

#fileObject

Get the filename for the error



105
106
107
# File 'ext/nokogiri/xml_syntax_error.c', line 105

def file
  cstruct[:file].null? ? nil : cstruct[:file]
end

#initialize_copy(old_copy) ⇒ Object

Initialize a copy of the old_copy



198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'ext/nokogiri/xml_syntax_error.c', line 198

static VALUE initialize_copy(VALUE self, VALUE _old_copy)
{
  if(!rb_obj_is_kind_of(_old_copy, cNokogiriXmlSyntaxError))
    rb_raise(rb_eArgError, "node must be a Nokogiri::XML::SyntaxError");

  xmlErrorPtr error, old_error;
  Data_Get_Struct(self, xmlError, error);
  Data_Get_Struct(_old_copy, xmlError, old_error);

  xmlCopyError(old_error, error);

  return message;
}

#int1Object

Extra number information



37
38
39
# File 'ext/nokogiri/xml_syntax_error.c', line 37

def int1
  cstruct[:int1]
end

#levelObject

Get the error level



120
121
122
# File 'ext/nokogiri/xml_syntax_error.c', line 120

def level
  cstruct[:level]
end

#lineObject

Get the line number of the error



92
93
94
# File 'ext/nokogiri/xml_syntax_error.c', line 92

def line
  cstruct[:line]
end

#messageObject Also known as: inspect, to_s

Get the human readable message.



159
160
161
162
# File 'ext/nokogiri/xml_syntax_error.c', line 159

def message
  val = cstruct[:message]
  val.null? ? nil : val.read_string
end

#message=Object

Set the human readable message.



173
174
175
176
177
178
# File 'ext/nokogiri/xml_syntax_error.c', line 173

def message=(string)
  unless cstruct[:message].null?
    LibXML.xmlFree(cstruct[:message])
  end
  cstruct[:message] = string
end

#none?Boolean

return true if this is a non error

Returns:

  • (Boolean)


13
14
15
# File 'lib/nokogiri/xml/syntax_error.rb', line 13

def none?
  level == 0
end

#str1Object

Extra string information



78
79
80
# File 'ext/nokogiri/xml_syntax_error.c', line 78

def str1
  cstruct[:str1].null? ? nil : cstruct[:str1]
end

#str2Object

Extra string information



64
65
66
# File 'ext/nokogiri/xml_syntax_error.c', line 64

def str2
  cstruct[:str].null? ? nil : cstruct[:str]
end

#str3Object

Extra string information



50
51
52
# File 'ext/nokogiri/xml_syntax_error.c', line 50

def str3
  cstruct[:str3].null? ? nil : cstruct[:str3]
end

#warning?Boolean

return true if this is a warning

Returns:

  • (Boolean)


19
20
21
# File 'lib/nokogiri/xml/syntax_error.rb', line 19

def warning?
  level == 1
end