class Nokogiri::XML::SAX::PushParser
PushParser can parse a document that is fed to it manually. It must be given a SAX::Document object which will be called with SAX events as the document is being parsed.
Calling PushParser#<< writes XML to the parser, calling any SAX callbacks it can.
PushParser#finish tells the parser that the document is finished and calls the end_document SAX method.
Example:
parser = PushParser.new(Class.new(XML::SAX::Document) {
def start_document
puts "start document called"
end
}.new)
parser << "<div>hello<"
parser << "/div>"
parser.finish
Attributes
The Nokogiri::XML::SAX::Document on which the PushParser will be operating
Public Class Methods
# File lib/nokogiri/xml/sax/push_parser.rb, line 35 def initialize(doc = XML::SAX::Document.new, file_name = nil, encoding = "UTF-8") @document = doc @encoding = encoding @sax_parser = XML::SAX::Parser.new(doc) ## Create our push parser context initialize_native(@sax_parser, file_name) end
Create a new PushParser with doc as the SAX Document, providing an optional file_name and encoding
Public Instance Methods
# File lib/nokogiri/xml/sax/push_parser.rb, line 55
def finish
write("", true)
end Finish the parsing. This method is only necessary for Nokogiri::XML::SAX::Document#end_document to be called.
static VALUE
get_options(VALUE self)
{
xmlParserCtxtPtr ctx;
Data_Get_Struct(self, xmlParserCtxt, ctx);
return INT2NUM(ctx->options);
} static VALUE
set_options(VALUE self, VALUE options)
{
xmlParserCtxtPtr ctx;
Data_Get_Struct(self, xmlParserCtxt, ctx);
if (xmlCtxtUseOptions(ctx, (int)NUM2INT(options)) != 0) {
rb_raise(rb_eRuntimeError, "Cannot set XML parser context options");
}
return Qnil;
} static VALUE
get_replace_entities(VALUE self)
{
xmlParserCtxtPtr ctx;
Data_Get_Struct(self, xmlParserCtxt, ctx);
if (0 == ctx->replaceEntities) {
return Qfalse;
} else {
return Qtrue;
}
} Should this parser replace entities? & will get converted to ‘&’ if set to true
static VALUE
set_replace_entities(VALUE self, VALUE value)
{
xmlParserCtxtPtr ctx;
Data_Get_Struct(self, xmlParserCtxt, ctx);
if (Qfalse == value) {
ctx->replaceEntities = 0;
} else {
ctx->replaceEntities = 1;
}
return value;
} Should this parser replace entities? & will get converted to ‘&’ if set to true
# File lib/nokogiri/xml/sax/push_parser.rb, line 47 def write(chunk, last_chunk = false) native_write(chunk, last_chunk) end
Write a chunk of XML to the PushParser. Any callback methods that can be called will be called immediately.
© 2008–2023 by Mike Dalessio, Aaron Patterson, Yoko Harada, Akinori MUSHA, John Shahid,
Karol Bucek, Sam Ruby, Craig Barnes, Stephen Checkoway, Lars Kanis, Sergio Arbeo,
Timothy Elliott, Nobuyoshi Nakada, Charles Nutter, Patrick MahoneyLicensed under the MIT License.
https://nokogiri.org/rdoc/Nokogiri/XML/SAX/PushParser.html