Parse options for passing to Nokogiri.XML
or Nokogiri.HTML
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.
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)))
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)
You can also setup parse combinations in the block passed to Nokogiri.XML
or Nokogiri.HTML
Nokogiri.XML('<content>Chapter 1</content') {|config| config.recover.noent}
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
line numbers stored as long int (instead of a short int)
compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree)
the default options used for parsing HTML
documents
the default options used for parsing XML
schemas
the default options used for parsing XML
documents
the default options used for parsing XSLT
stylesheets
Default DTD
attributes
Load external subsets
validate with the DTD
relax any hardcoded limit from the parser
do not fixup XINCLUDE
xml:base uris
remove blank nodes
merge CDATA
as text nodes
Do not reuse the context dictionary
Substitute entities
suppress error reports
Forbid network access. Recommended for dealing with untrusted documents.
suppress warning reports
do not generate XINCLUDE
START/END nodes
remove redundant namespaces declarations
parse using XML-1.0 before update 5
pedantic error reporting
Recover from errors
use the SAX1
interface internally
Strict parsing
Implement XInclude substitution
# File lib/nokogiri/xml/parse_options.rb, line 86 def initialize(options = STRICT) @options = options end
# File lib/nokogiri/xml/parse_options.rb, line 118 def ==(other) other.to_i == to_i end
# File lib/nokogiri/xml/parse_options.rb, line 124 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 109 def strict @options &= ~RECOVER self end
# File lib/nokogiri/xml/parse_options.rb, line 114 def strict? @options & RECOVER == STRICT end
© 2008–2018 Aaron Patterson, Mike Dalessio, Charles Nutter, Sergio Arbeo,
Patrick Mahoney, Yoko Harada, Akinori MUSHA, John Shahid, Lars Kanis
Licensed under the MIT License.
https://nokogiri.org/rdoc/Nokogiri/XML/ParseOptions.html