Class: Nokogiri::XML::SAX::ParserContext
- Inherits:
-
Object
- Object
- Nokogiri::XML::SAX::ParserContext
- Defined in:
- lib/nokogiri/xml/sax/parser_context.rb,
lib/nokogiri/ffi/xml/sax/parser_context.rb,
ext/nokogiri/xml_sax_parser_context.c,
ext/nokogiri/html_sax_parser_context.c
Overview
Context for XML SAX parsers. This class is usually not instantiated by the user. Instead, you should be looking at Nokogiri::XML::SAX::Parser
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cstruct ⇒ Object
Returns the value of attribute cstruct.
-
#reader_callback ⇒ Object
Returns the value of attribute reader_callback.
Class Method Summary collapse
-
.parse_file(filename) ⇒ Object
Parse file given
filename
. -
.parse_io(io, encoding) ⇒ Object
Parse
io
object withencoding
. -
.parse_memory(data) ⇒ Object
Parse the XML stored in memory in
data
. - .new(thing, encoding = 'UTF-8') ⇒ Object
Instance Method Summary collapse
-
#parse_with(sax_handler) ⇒ Object
Use
sax_handler
and parse the current document. -
#replace_entities ⇒ Object
Should this parser replace entities? & will get converted to ‘&’ if set to true.
-
#replace_entities=(boolean) ⇒ Object
Should this parser replace entities? & will get converted to ‘&’ if set to true.
Instance Attribute Details
#cstruct ⇒ Object
Returns the value of attribute cstruct.
6 7 8 |
# File 'lib/nokogiri/ffi/xml/sax/parser_context.rb', line 6 def cstruct @cstruct end |
#reader_callback ⇒ Object
Returns the value of attribute reader_callback.
7 8 9 |
# File 'lib/nokogiri/ffi/xml/sax/parser_context.rb', line 7 def reader_callback @reader_callback end |
Class Method Details
.parse_file(filename) ⇒ Object
Parse file given filename
44 45 46 47 48 49 |
# File 'ext/nokogiri/xml_sax_parser_context.c', line 44 def self.file filename ctx = LibXML.xmlCreateFileParserCtxt filename pc = allocate pc.cstruct = LibXML::XmlParserContext.new ctx pc end |
.parse_io(io, encoding) ⇒ Object
Parse io
object with encoding
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'ext/nokogiri/xml_sax_parser_context.c', line 22 def self.io io, encoding reader_callback = IoCallbacks.reader(io) # keep a reference to prevent it from being GC'd sax_ctx = LibXML.xmlCreateIOParserCtxt( nil, nil, reader_callback, nil, nil, encoding ) pc = allocate pc.cstruct = LibXML::XmlParserContext.new sax_ctx pc.reader_callback = reader_callback pc end |
.parse_memory(data) ⇒ Object
Parse the XML stored in memory in data
56 57 58 59 60 61 62 63 64 65 |
# File 'ext/nokogiri/xml_sax_parser_context.c', line 56 def self.memory data raise(ArgumentError, 'data cannot be nil') if data.nil? raise('data cannot be empty') if data.length == 0 ctx = LibXML::XmlParserContext.new( LibXML.xmlCreateMemoryParserCtxt data, data.length ) pc = allocate pc.cstruct = ctx pc end |
Instance Method Details
#parse_with(sax_handler) ⇒ Object
Use sax_handler
and parse the current document
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'ext/nokogiri/xml_sax_parser_context.c', line 76 def parse_with sax_handler, type = :xml raise ArgumentError unless XML::SAX::Parser === sax_handler sax = sax_handler.cstruct cstruct[:sax] = sax sax_handler.instance_variable_set(:@ctxt, cstruct) LibXML.send(:"#{type}ParseDocument", cstruct) cstruct[:sax] = nil LibXML.xmlFreeDoc cstruct[:myDoc] unless cstruct[:myDoc].null? end |
#replace_entities ⇒ Object
Should this parser replace entities? & will get converted to ‘&’ if set to true
128 129 130 |
# File 'ext/nokogiri/xml_sax_parser_context.c', line 128 def replace_entities self.cstruct[:replaceEntities] == 0 ? false : true end |
#replace_entities=(boolean) ⇒ Object
Should this parser replace entities? & will get converted to ‘&’ if set to true
108 109 110 |
# File 'ext/nokogiri/xml_sax_parser_context.c', line 108 def replace_entities=(value) self.cstruct[:replaceEntities] = value ? 1 : 0 end |