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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:36:13+00:00 2026-05-23T22:36:13+00:00

the to_xml to activerecord include the xml declaration as follows. <?xml version=1.0 encoding=UTF-8?> How

  • 0

the to_xml to activerecord include the xml declaration as follows.

<?xml version="1.0" encoding="UTF-8"?>

How do we change the version to 1.1 and also change the encoding?

We can use to_xml(:skip_instruct => true) to hide the declaration altogether.

  • 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-23T22:36:14+00:00Added an answer on May 23, 2026 at 10:36 pm

    If you are using restfull routes then visiting some_url.xml will give you the results as you have described. If this is the way you are serving your xml then you can define your own xml builder template. It will work in exactly the same way as a view works
    here is an example

    your controller action

      def show
        @obj = SomeClass.find(params[:id])
    
        respond_to do |format|
          format.html # show.html.erb
          format.xml  { render :layout => false }
        end
      end
    

    Then in the views folder where you would normally place the show.html.erb create a show.xml.builder file with the contents looking something like this

    xml.someclass do
      xml.id(@obj.id)
      xml.name(@obj.name)
    end
    

    In this template you can then add <?xml version="1.1" encoding="UTF-8"?> or whatever xml declarations you wish to add

    UPDATE
    You don’t need to be serving views, just a RESTfull route, a controller and an action that has a respond_to that respondes to the XML format. Rails will pick up that you want to render xml and will look for .xml.erb file in the views folder named after the action in exactly the same way as views work

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

Sidebar

Related Questions

The default behavior of XML serialization (to_xml) for ActiveRecord objects will emit 'type' and
I have an ActiveRecord model that I would like to convert to xml, but
I would like to use Linq to Xml to get a single XElement from
Okay, I know you can override the to_xml method for a single instance of
New to xml. Looking for XPath to search a xml file with python ElementTree
I'm a LINQ to XML newbie, and a KML newbie as well; so bear
I'm serializing to XML my class where one of properties has type List<string>. public
I plan to serialize a Django model to XML when it's saved or updated.
I'm trying to parse objects to XML in Delphi, so I read about calling
I would like to read/write encrypted XML files using LINQ to XML. Does anyone

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.