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 3845150
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:12:00+00:00 2026-05-19T16:12:00+00:00

Nokogiri saves XML attributes with double quotes, even if DOM it read had single

  • 0

Nokogiri saves XML attributes with double quotes, even if DOM it read had single quotes.
This is totally legitimate of course, but it introduces annoying changes to file contents even when DOM didn’t change, making it harder for tools like diff and git to figure out what happened.

Can I force it to use single quotes (or even better, keep whatever quoting style there was in the original if nothing was modified)?

REXML has this for setting single/double quote:

doc.context[:attribute_quote] = :quote 

I couldn’t find anything similar for nokogiri.

Is it possible to have it save documents with single quotes?

  • 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-05-19T16:12:01+00:00Added an answer on May 19, 2026 at 4:12 pm

    It looks like the answer is no; not as the library is currently written, and maybe not at all. Tracing the call path for a node’s serialization:

    • Nokogiri::XML::Node#to_s calls to_xml
    • Nokogiri::XML::Node#to_xml calls serialize (sets a few default options)
    • Nokogiri::XML::Node#serialize calls write_to
    • Nokogiri::XML::Node#write_to calls native_write_to
    • Nokogiri::XML::Node#native_write_to calls native_write_to, which looks like this:

    &bsp;

    def native_write_to(io, encoding, indent_string, options)
      set_xml_indent_tree_output 1
      set_xml_tree_indent_string indent_string
      savectx = LibXML.xmlSaveToIO(IoCallbacks.writer(io), nil, nil, encoding, options)
      LibXML.xmlSaveTree(savectx, cstruct)
      LibXML.xmlSaveClose(savectx)
      io
    end
    

    So, you are at the mercy of libxml at this point. Googling for libxml serialize single quote attributes does not immediately turn up any smoking guns.

    I think you should file a feature request and see what sort of tenderlovin’ you can get. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this nokogiri object: element.first => #<Nokogiri::XML::Element:0x3fc0cf8ac4b8 name=a attributes=[#<Nokogiri::XML::Attr:0x3fc0cf8ac454 name=class value=fl>, #<Nokogiri::XML::Attr:0x3fc0cf8ac42c name=id
I'm using nokogiri with an xml document that looks something like this: <songs> <song>
Using this xslt file found on this blog to pretty print xml using Nokogiri,
I am parsing some XML using Nokogiri and XPath. When I do this: doc.xpath('//Order/child::node()').each
Given a Nokogiri::XML::Node object, how can I remove some of its dom nodes? For
I'm having trouble editing an XML file. I'm currently trying to use Nokogiri ,
I'm newbie to Nokogiri ruby gem. I'm wondering how to read and write back
This Ruby code using Nokogiri doc.xpath(//tbody).remove removes the children of the <tbody> (as well
I have used this command to send xml files to a web service named
I am trying to parse a bunch of XML files. I am using Nokogiri,

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.