Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8561287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:28:10+00:00 2026-06-11T16:28:10+00:00

Both puts Nokogiri::XML(xml) and puts Nokogiri.parse(xml) return the same XML. And yes, they both

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:28:12+00:00Added an answer on June 11, 2026 at 4:28 pm

    Nokogiri.parse just attempts to detect if the string passed to it is HTML, then creates/returns either a Nokogiri::XML or Nokogiri::HTML instance with a preset ParseOption:

    def parse string, url = nil, encoding = nil, options = nil
      doc =
        if string.respond_to?(:read) ||
          string =~ /^\s*<[^Hh>]*html/i # Probably html
          Nokogiri.HTML(
            string,
            url,
            encoding, options || XML::ParseOptions::DEFAULT_HTML
          )
        else
          Nokogiri.XML(string, url, encoding,
                        options || XML::ParseOptions::DEFAULT_XML)
        end
      yield doc if block_given?
      doc
    end
    

    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:

    >> Nokogiri.parse(xml) == Nokogiri.parse(xml)
    => false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Nokogiri to parse an html. I need both the content and image
Consider the following code: require 'nokogiri' # v1.5.2 doc = Nokogiri.XML('<body><a name=foo>ick</a></body>') puts doc.to_html
Both in Actionscript3 and Javascript these statements give the same result: /\S/.test(null) => true
I'm using the CSS3 property: resize: both; overflow: none; This puts a resize handle
I'm busy with a simple application. It reads xml and puts the information in
I would like to parse a table using Nokogiri. I'm doing it this way
I'm using will_paginate to display data returned from a query that includes both a
I have tried both strcat and strcat_s, but they both crash. Does anyone know
How can I make the code below work, so that both puts display 1
The situation is this: You have two classes that both implement the same interface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.