def parse string_or_io, options = nil
options ||= (document.html? ? ParseOptions::DEFAULT_HTML : ParseOptions::DEFAULT_XML)
if Fixnum === options
options = Nokogiri::XML::ParseOptions.new(options)
end
yield options if block_given?
contents = string_or_io.respond_to?(:read) ?
string_or_io.read :
string_or_io
return Nokogiri::XML::NodeSet.new(document) if contents.empty?
error_count = document.errors.length
node_set = in_context(contents, options.to_i)
if node_set.empty? and document.errors.length > error_count and options.recover?
fragment = Nokogiri::HTML::DocumentFragment.parse contents
node_set = fragment.children
end
node_set
end