Both puts Nokogiri::XML(xml) and puts Nokogiri.parse(xml) return the same XML.
And yes, they both return XML:
> Nokogiri::XML(xml).class
=> Nokogiri::XML::Document
> Nokogiri.parse(xml).class
=> Nokogiri::XML::Document
Yet when comparing the returned values, I get:
> Nokogiri.parse(xml) === Nokogiri::XML(xml)
=> false
> Nokogiri.parse(xml) == Nokogiri::XML(xml)
=> false
What is difference between Nokogiri::XML and Nokogiri.parse?
Nokogiri.parsejust attempts to detect if the string passed to it is HTML, then creates/returns either aNokogiri::XMLorNokogiri::HTMLinstance with a preset ParseOption:https://github.com/sparklemotion/nokogiri/blob/master/lib/nokogiri.rb#L66
The comparisons return false because == isn’t comparing the contents of the object, just that they’re different instances: