class Nokogiri::XML::Document

def parse(string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML)

Experimental RBS support (using type sampling data from the type_fusion project).

def parse: (String string_or_io, ?nil url, ?nil encoding, ?Nokogiri::XML::ParseOptions options) -> Nokogiri::XML::Document

This signature was generated using 1 sample from 1 application.


Nokogiri.XML() is a convenience method which will call this method.

set) by default.
and that module's DEFAULT_XML constant for what's set (and not
Nokogiri::XML::ParseOptions for a complete list of options;
does not attempt to load DTDs or access the network. See
By default, Nokogiri treats documents as untrusted, and so

parse options may be set.
+block+ (optional) is passed a configuration object on which

Nokogiri::XML::ParseOptions for more information.
parsing, such as Nokogiri::XML::ParseOptions::RECOVER. See the
+options+ (optional) is a configuration object that sets options during

the document.
+encoding+ (optional) is the encoding that should be used when processing

+url+ (optional) is the URI where this document is located.

_read_ and _close_ such as an IO, or StringIO.
+string_or_io+ may be a String, or any object that responds to

Parse an XML file.
def parse(string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML)
  options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
  yield options if block_given?
  url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
  if empty_doc?(string_or_io)
    if options.strict?
      raise Nokogiri::XML::SyntaxError, "Empty document"
    else
      return encoding ? new.tap { |i| i.encoding = encoding } : new
    end
  end
  doc = if string_or_io.respond_to?(:read)
    if string_or_io.is_a?(Pathname)
      # resolve the Pathname to the file and open it as an IO object, see #2110
      string_or_io = string_or_io.expand_path.open
      url ||= string_or_io.path
    end
    read_io(string_or_io, url, encoding, options.to_i)
  else
    # read_memory pukes on empty docs
    read_memory(string_or_io, url, encoding, options.to_i)
  end
  # do xinclude processing
  doc.do_xinclude(options) if options.xinclude?
  doc
end