Class: Nokogiri::HTML4::SAX::ParserContext
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
|
|
|
Instance Chain:
|
|
| Inherits: |
Nokogiri::XML::SAX::ParserContext
|
| Defined in: | lib/nokogiri/html4/sax/parser_context.rb, ext/nokogiri/html4_sax_parser_context.c |
Overview
Context object to invoke the ::Nokogiri::HTML4 SAX parser on the SAX::Document handler.
š” This class is usually not instantiated by the user. Use Parser instead.
Class Method Summary
- .native_file(rb_filename, rb_encoding) Internal use only
- .native_memory(rb_input, rb_encoding) Internal use only
::Nokogiri::XML::SAX::ParserContext - Inherited
| .file | Create a parser context for the file at |
| .io | Create a parser context for an |
| .memory | Create a parser context for the |
| .new | Create a parser context for an IO or a String. |
| .resolve_encoding, .native_file, .native_io, .native_memory | |
Instance Attribute Summary
::Nokogiri::XML::SAX::ParserContext - Inherited
| #recovery | Inspect whether this parser will recover from parsing errors. |
| #recovery= | Controls whether this parser will recover from parsing errors. |
| #replace_entities | See Document@Entity+Handling for an explanation of the behavior controlled by this flag. |
| #replace_entities= | See Document@Entity+Handling for an explanation of the behavior controlled by this flag. |
Instance Method Summary
::Nokogiri::XML::SAX::ParserContext - Inherited
| #column |
|
| #line |
|
| #parse_with | Use |
Constructor Details
This class inherits a constructor from Nokogiri::XML::SAX::ParserContext
Class Method Details
.native_file(rb_filename, rb_encoding)
# File 'ext/nokogiri/html4_sax_parser_context.c', line 35
static VALUE
noko_html4_sax_parser_context_s_native_file(VALUE rb_class, VALUE rb_filename, VALUE rb_encoding)
{
if (!NIL_P(rb_encoding) && !rb_obj_is_kind_of(rb_encoding, rb_cEncoding)) {
rb_raise(rb_eTypeError, "argument must be an Encoding object");
}
htmlParserCtxtPtr c_context = htmlCreateFileParserCtxt(StringValueCStr(rb_filename), NULL);
if (!c_context) {
rb_raise(rb_eRuntimeError, "failed to create xml sax parser context");
}
noko_xml_sax_parser_context_set_encoding(c_context, rb_encoding);
if (c_context->sax) {
xmlFree(c_context->sax);
c_context->sax = NULL;
}
return noko_xml_sax_parser_context_wrap(rb_class, c_context);
}
.native_memory(rb_input, rb_encoding)
# File 'ext/nokogiri/html4_sax_parser_context.c', line 6
static VALUE
noko_html4_sax_parser_context_s_native_memory(VALUE rb_class, VALUE rb_input, VALUE rb_encoding)
{
Check_Type(rb_input, T_STRING);
if (!(int)RSTRING_LEN(rb_input)) {
rb_raise(rb_eRuntimeError, "input string cannot be empty");
}
if (!NIL_P(rb_encoding) && !rb_obj_is_kind_of(rb_encoding, rb_cEncoding)) {
rb_raise(rb_eTypeError, "argument must be an Encoding object");
}
htmlParserCtxtPtr c_context =
htmlCreateMemoryParserCtxt(StringValuePtr(rb_input), (int)RSTRING_LEN(rb_input));
if (!c_context) {
rb_raise(rb_eRuntimeError, "failed to create xml sax parser context");
}
noko_xml_sax_parser_context_set_encoding(c_context, rb_encoding);
if (c_context->sax) {
xmlFree(c_context->sax);
c_context->sax = NULL;
}
return noko_xml_sax_parser_context_wrap(rb_class, c_context);
}
Instance Method Details
#parse_with(rb_sax_parser)
[ GitHub ]# File 'ext/nokogiri/html4_sax_parser_context.c', line 57
static VALUE
noko_html4_sax_parser_context__parse_with(VALUE rb_context, VALUE rb_sax_parser)
{
htmlParserCtxtPtr ctxt;
htmlSAXHandlerPtr sax;
if (!rb_obj_is_kind_of(rb_sax_parser, cNokogiriXmlSaxParser)) {
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");
}
ctxt = noko_xml_sax_parser_context_unwrap(rb_context);
sax = noko_xml_sax_parser_unwrap(rb_sax_parser);
ctxt->sax = sax;
ctxt->userData = ctxt; /* so we can use libxml2/SAX2.c handlers if we want to */
ctxt->_private = (void *)rb_sax_parser;
xmlSetStructuredErrorFunc(NULL, NULL);
/* although we're calling back into Ruby here, we don't need to worry about exceptions, because we
* don't have any cleanup to do. The only memory we need to free is handled by
* xml_sax_parser_context_type_free */
htmlParseDocument(ctxt);
return Qnil;
}