class Nokogiri::XML::ParseOptions
Parse options for passing to Nokogiri.XML
or Nokogiri.HTML
Building combinations of parse options¶ ↑
You can build your own combinations of these parse options by using any of the following methods: Note: All examples attempt to set the RECOVER
& NOENT
options.
- Ruby’s bitwise operators
-
You can use the Ruby bitwise operators to set various combinations.
Nokogiri.XML('<content>Chapter 1</content', nil, nil, Nokogiri::XML::ParseOptions.new((1 << 0) | (1 << 1)))
- Method chaining
-
Every option has an equivalent method in lowercase. You can chain these methods together to set various combinations.
Nokogiri.XML('<content>Chapter 1</content', nil, nil, Nokogiri::XML::ParseOptions.new.recover.noent)
- Using Ruby Blocks
-
You can also setup parse combinations in the block passed to
Nokogiri.XML
orNokogiri.HTML
Nokogiri.XML('<content>Chapter 1</content') {|config| config.recover.noent}
Removing particular parse options¶ ↑
You can also remove options from an instance of ParseOptions
dynamically. Every option has an equivalent no{option}
method in lowercase. You can call these methods on an instance of ParseOptions
to remove the option. Note that this is not available for STRICT
.
# Setting the RECOVER & NOENT options... options = Nokogiri::XML::ParseOptions.new.recover.noent # later... options.norecover # Removes the Nokogiri::XML::ParseOptions::RECOVER option options.nonoent # Removes the Nokogiri::XML::ParseOptions::NOENT option
Constants
- BIG_LINES
-
line numbers stored as long int (instead of a short int)
- COMPACT
-
compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree)
- DEFAULT_HTML
-
the default options used for parsing
HTML
documents - DEFAULT_SCHEMA
-
the default options used for parsing
XML
schemas - DEFAULT_XML
-
the default options used for parsing
XML
documents - DEFAULT_XSLT
-
the default options used for parsing
XSLT
stylesheets - DTDATTR
-
Default
DTD
attributes - DTDLOAD
-
Load external subsets
- DTDVALID
-
validate with the
DTD
- HUGE
-
relax any hardcoded limit from the parser
- NOBASEFIX
-
do not fixup
XINCLUDE
xml:base uris - NOBLANKS
-
remove blank nodes
- NOCDATA
-
merge
CDATA
as text nodes - NODICT
-
Do not reuse the context dictionary
- NOENT
-
Substitute entities
- NOERROR
-
suppress error reports
- NONET
-
Forbid network access. Recommended for dealing with untrusted documents.
- NOWARNING
-
suppress warning reports
- NOXINCNODE
-
do not generate
XINCLUDE
START/END nodes - NSCLEAN
-
remove redundant namespaces declarations
- OLD10
-
parse using XML-1.0 before update 5
- PEDANTIC
-
pedantic error reporting
- RECOVER
-
Recover from errors
- SAX1
-
use the
SAX1
interface internally - STRICT
-
Strict parsing
- XINCLUDE
-
Implement XInclude substitution
Attributes
Public Class Methods
# File lib/nokogiri/xml/parse_options.rb, line 86 def initialize(options = STRICT) @options = options end
Public Instance Methods
# File lib/nokogiri/xml/parse_options.rb, line 119 def ==(other) other.to_i == to_i end
# File lib/nokogiri/xml/parse_options.rb, line 125 def inspect options = [] self.class.constants.each do |k| options << k.downcase if send(:"#{k.downcase}?") end super.sub(/>$/, " " + options.join(", ") + ">") end
# File lib/nokogiri/xml/parse_options.rb, line 110 def strict @options &= ~RECOVER self end
# File lib/nokogiri/xml/parse_options.rb, line 115 def strict? @options & RECOVER == STRICT end