### Home Classes Methods

### In Files

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

### Parent

Object

### Methods

- ::file
- ::io
- ::memory
- ::new
- #column
- #line
- #parse_with
- #replace_entities
- #replace_entities=

### 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::ParserContext

Context for XML SAX parsers. This class is usually not instantiated by the user. Instead, you should be looking at Nokogiri::XML::SAX::Parser

### Public Class Methods

parse_file(filename) click to toggle source

Parse file given `filename`

    static VALUE parse_file(VALUE klass, VALUE filename)
    {
      xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
      return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
    }

parse_io(io, encoding) click to toggle source

Parse `io` object with `encoding`

    static VALUE
    parse_io(VALUE klass, VALUE io, VALUE encoding)
    {
        xmlParserCtxtPtr ctxt;
        xmlCharEncoding enc = (xmlCharEncoding)NUM2INT(encoding);

        ctxt = xmlCreateIOParserCtxt(NULL, NULL,
                                     (xmlInputReadCallback)io_read_callback,
                                     (xmlInputCloseCallback)io_close_callback,
                                     (void *)io, enc);
        if (ctxt->sax) {
            xmlFree(ctxt->sax);
            ctxt->sax = NULL;
        }

        return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
    }

parse_memory(data) click to toggle source

Parse the XML stored in memory in `data`

    static VALUE
    parse_memory(VALUE klass, VALUE data)
    {
        xmlParserCtxtPtr ctxt;

        if (NIL_P(data))
            rb_raise(rb_eArgError, "data cannot be nil");
        if (!(int)RSTRING_LEN(data))
            rb_raise(rb_eRuntimeError, "data cannot be empty");

        ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data),
                                         (int)RSTRING_LEN(data));
        if (ctxt->sax) {
            xmlFree(ctxt->sax);
            ctxt->sax = NULL;
        }

        return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
    }

new(thing, encoding = 'UTF-8') click to toggle source

    # File lib/nokogiri/xml/sax/parser_context.rb, line 9
    def self.new thing, encoding = 'UTF-8'
      [:read, :close].all? { |x| thing.respond_to?(x) } ?
        io(thing, Parser::ENCODINGS[encoding]) : memory(thing)
    end

### Public Instance Methods

column click to toggle source

Get the current column the parser context is processing.

    static VALUE column(VALUE self)
    {
      xmlParserCtxtPtr ctxt;
      xmlParserInputPtr io;

      Data_Get_Struct(self, xmlParserCtxt, ctxt);

      io = ctxt->input;
      if(io)
        return INT2NUM(io->col);

      return Qnil;
    }

line click to toggle source

Get the current line the parser context is processing.

    static VALUE line(VALUE self)
    {
      xmlParserCtxtPtr ctxt;
      xmlParserInputPtr io;

      Data_Get_Struct(self, xmlParserCtxt, ctxt);

      io = ctxt->input;
      if(io)
        return INT2NUM(io->line);

      return Qnil;
    }

parse_with(sax_handler) click to toggle source

Use `sax_handler` and parse the current document

    static VALUE
    parse_with(VALUE self, VALUE sax_handler)
    {
        xmlParserCtxtPtr ctxt;
        xmlSAXHandlerPtr sax;

        if (!rb_obj_is_kind_of(sax_handler, cNokogiriXmlSaxParser))
            rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");

        Data_Get_Struct(self, xmlParserCtxt, ctxt);
        Data_Get_Struct(sax_handler, xmlSAXHandler, sax);

        /* Free the sax handler since we'll assign our own */
        if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler)
            xmlFree(ctxt->sax);

        ctxt->sax = sax;
        ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);

        rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt);

        return Qnil;
    }

replace_entities click to toggle source

Should this parser replace entities? &amp; will get converted to ‘&’ if set to true

    static VALUE get_replace_entities(VALUE self)
    {
      xmlParserCtxtPtr ctxt;
      Data_Get_Struct(self, xmlParserCtxt, ctxt);

      if(0 == ctxt->replaceEntities)
        return Qfalse;
      else
        return Qtrue;
    }

replace_entities=(boolean) click to toggle source

Should this parser replace entities? &amp; will get converted to ‘&’ if set to true

    static VALUE set_replace_entities(VALUE self, VALUE value)
    {
      xmlParserCtxtPtr ctxt;
      Data_Get_Struct(self, xmlParserCtxt, ctxt);

      if(Qfalse == value)
        ctxt->replaceEntities = 0;
      else
        ctxt->replaceEntities = 1;

      return value;
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.