### Home Classes Methods

### In Files

- lib/nokogiri/xml/sax/push_parser.rb
- ext/nokogiri/html_sax_parser_context.c

### Parent

Object

### Methods

- ::new
- #<<
- #finish
- #options
- #options=
- #write

### Files

- CHANGELOG.ja.rdoc
- CHANGELOG.rdoc
- C_CODING_STYLE.rdoc
- Manifest.txt
- README.ja.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- Nokogiri
- Nokogiri::CSS
- Nokogiri::CSS::Node
- Nokogiri::CSS::Parser
- Nokogiri::CSS::SyntaxError
- Nokogiri::CSS::Tokenizer
- Nokogiri::CSS::Tokenizer::ScanError
- Nokogiri::Decorators
- Nokogiri::Decorators::Slop
- Nokogiri::EncodingHandler
- Nokogiri::HTML
- Nokogiri::HTML::Builder
- Nokogiri::HTML::Document
- Nokogiri::HTML::Document::EncodingReader
- Nokogiri::HTML::Document::EncodingReader::JumpSAXHandler
- Nokogiri::HTML::DocumentFragment
- Nokogiri::HTML::ElementDescription
- Nokogiri::HTML::EntityDescription
- Nokogiri::HTML::EntityLookup
- Nokogiri::HTML::SAX
- Nokogiri::HTML::SAX::Parser
- Nokogiri::HTML::SAX::ParserContext
- Nokogiri::HTML::SAX::PushParser
- Nokogiri::SyntaxError
- Nokogiri::XML
- Nokogiri::XML::Attr
- Nokogiri::XML::AttributeDecl
- Nokogiri::XML::Builder
- Nokogiri::XML::CDATA
- Nokogiri::XML::CharacterData
- Nokogiri::XML::Comment
- Nokogiri::XML::DTD
- Nokogiri::XML::Document
- Nokogiri::XML::DocumentFragment
- Nokogiri::XML::Element
- Nokogiri::XML::ElementContent
- Nokogiri::XML::ElementDecl
- Nokogiri::XML::EntityDecl
- Nokogiri::XML::EntityReference
- Nokogiri::XML::Namespace
- Nokogiri::XML::Node
- Nokogiri::XML::Node::SaveOptions
- Nokogiri::XML::NodeSet
- Nokogiri::XML::Notation
- Nokogiri::XML::PP
- Nokogiri::XML::PP::CharacterData
- Nokogiri::XML::PP::Node
- Nokogiri::XML::ParseOptions
- Nokogiri::XML::ProcessingInstruction
- Nokogiri::XML::Reader
- Nokogiri::XML::RelaxNG
- Nokogiri::XML::SAX
- Nokogiri::XML::SAX::Document
- Nokogiri::XML::SAX::Parser
- Nokogiri::XML::SAX::Parser::Attribute
- Nokogiri::XML::SAX::ParserContext
- Nokogiri::XML::SAX::PushParser
- Nokogiri::XML::Schema
- Nokogiri::XML::SyntaxError
- Nokogiri::XML::Text
- Nokogiri::XML::XPath
- Nokogiri::XML::XPath::SyntaxError
- Nokogiri::XML::XPathContext
- Nokogiri::XSLT
- Nokogiri::XSLT::Stylesheet
- XSD
- XSD::XMLParser
- XSD::XMLParser::Nokogiri
- Object

No matching classes.

# 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

document[RW]

The Nokogiri::XML::SAX::Document on which the PushParser will be operating

### Public Class Methods

new(doc = XML::SAX::Document.new, file_name = nil, encoding = 'UTF-8') click to toggle source

Create a new PushParser with `doc` as the SAX Document, providing an optional `file_name` and `encoding`

    # File lib/nokogiri/xml/sax/push_parser.rb, line 34
    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

### Public Instance Methods

<<(chunk, last_chunk = false) click to toggle source
Alias for: write
finish() click to toggle source

Finish the parsing. This method is only necessary for Nokogiri::XML::SAX::Document#end_document to be called.

    # File lib/nokogiri/xml/sax/push_parser.rb, line 54
    def finish
      write '', true
    end

options() click to toggle source

    static VALUE get_options(VALUE self)
    {
      xmlParserCtxtPtr ctx;
      Data_Get_Struct(self, xmlParserCtxt, ctx);

      return INT2NUM(ctx->options);
    }

options=(p1) click to toggle source

    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;
    }

write(chunk, last_chunk = false) click to toggle source

Write a `chunk` of XML to the PushParser. Any callback methods that can be called will be called immediately.

    # File lib/nokogiri/xml/sax/push_parser.rb, line 46
    def write chunk, last_chunk = false
      native_write(chunk, last_chunk)
    end

Also aliased as: <<

[Validate]

Generated with the Darkfish Rdoc Generator 2.