class Nokogiri::XML::SAX::ParserContext
Context object to invoke the XML SAX parser on the SAX::Document handler.
💡 This class is usually not instantiated by the user. Use Nokogiri::XML::SAX::Parser instead.
Public Class Methods
Source
# File lib/nokogiri/xml/sax/parser_context.rb, line 97 def file(input, encoding = nil) native_file(input, resolve_encoding(encoding)) end
Create a parser context for the file at path.
- Parameters
-
path(String) The path to the input file -
encoding(optional) (Encoding, String) TheEncodingto use, or the name of an encoding to use (defaultnil, encoding will be autodetected)
💡 Calling this method directly is discouraged. Use Nokogiri::XML::SAX::Parser.parse_file which is more convenient for most use cases.
Source
# File lib/nokogiri/xml/sax/parser_context.rb, line 56 def io(input, encoding = nil) native_io(input, resolve_encoding(encoding)) end
Create a parser context for an input IO which will assume encoding
- Parameters
-
io(IO) The readable IO object from which to read input -
encoding(optional) (Encoding) TheEncodingto use, or the name of an encoding to use (defaultnil, encoding will be autodetected)
💡 Calling this method directly is discouraged. Use Nokogiri::XML::SAX::Parser parse methods which are more convenient for most use cases.
Source
# File lib/nokogiri/xml/sax/parser_context.rb, line 77 def memory(input, encoding = nil) native_memory(input, resolve_encoding(encoding)) end
Create a parser context for the input String.
- Parameters
-
input(String) The input string to be parsed. -
encoding(optional) (Encoding, String) TheEncodingto use, or the name of an encoding to use (defaultnil, encoding will be autodetected)
💡 Calling this method directly is discouraged. Use Nokogiri::XML::SAX::Parser parse methods which are more convenient for most use cases.
Source
# File lib/nokogiri/xml/sax/parser_context.rb, line 31 def new(input, encoding = nil) if [:read, :close].all? { |x| input.respond_to?(x) } io(input, encoding) else memory(input, encoding) end end
Create a parser context for an IO or a String. This is a shorthand method for ParserContext.io and ParserContext.memory.
- Parameters
-
input(IO, String) A String or a readable IO object -
encoding(optional) (Encoding) TheEncodingto use, or the name of an encoding to use (defaultnil, encoding will be autodetected)
If input quacks like a readable IO object, this method forwards to ParserContext.io, otherwise it forwards to ParserContext.memory.