--- !ruby/object:RI::MethodDescription 
aliases: []

block_params: 
comment: 
- !ruby/struct:SM::Flow::P 
  body: Builds an XML document to represent the model. Some configuration is available through <tt>options</tt>, however more complicated cases should override ActiveRecord's to_xml.
- !ruby/struct:SM::Flow::P 
  body: "By default the generated XML document will include the processing instruction and all object's attributes. For example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n  &lt;topic&gt;\n    &lt;title&gt;The First Topic&lt;/title&gt;\n    &lt;author-name&gt;David&lt;/author-name&gt;\n    &lt;id type=&quot;integer&quot;&gt;1&lt;/id&gt;\n    &lt;approved type=&quot;boolean&quot;&gt;false&lt;/approved&gt;\n    &lt;replies-count type=&quot;integer&quot;&gt;0&lt;/replies-count&gt;\n    &lt;bonus-time type=&quot;datetime&quot;&gt;2000-01-01T08:28:00+12:00&lt;/bonus-time&gt;\n    &lt;written-on type=&quot;datetime&quot;&gt;2003-07-16T09:28:00+1200&lt;/written-on&gt;\n    &lt;content&gt;Have a nice day&lt;/content&gt;\n    &lt;author-email-address&gt;david@loudthinking.com&lt;/author-email-address&gt;\n    &lt;parent-id&gt;&lt;/parent-id&gt;\n    &lt;last-read type=&quot;date&quot;&gt;2004-04-15&lt;/last-read&gt;\n  &lt;/topic&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "This behavior can be controlled with :only, :except, :skip_instruct, :skip_types and :dasherize. The :only and :except options are the same as for the #attributes method. The default is to dasherize all column names, to disable this, set :dasherize to false. To not have the column type included in the XML output, set :skip_types to true."
- !ruby/struct:SM::Flow::P 
  body: "For instance:"
- !ruby/struct:SM::Flow::VERB 
  body: "  topic.to_xml(:skip_instruct =&gt; true, :except =&gt; [ :id, :bonus_time, :written_on, :replies_count ])\n\n  &lt;topic&gt;\n    &lt;title&gt;The First Topic&lt;/title&gt;\n    &lt;author-name&gt;David&lt;/author-name&gt;\n    &lt;approved type=&quot;boolean&quot;&gt;false&lt;/approved&gt;\n    &lt;content&gt;Have a nice day&lt;/content&gt;\n    &lt;author-email-address&gt;david@loudthinking.com&lt;/author-email-address&gt;\n    &lt;parent-id&gt;&lt;/parent-id&gt;\n    &lt;last-read type=&quot;date&quot;&gt;2004-04-15&lt;/last-read&gt;\n  &lt;/topic&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: To include first level associations use :include
- !ruby/struct:SM::Flow::VERB 
  body: "  firm.to_xml :include =&gt; [ :account, :clients ]\n\n  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n  &lt;firm&gt;\n    &lt;id type=&quot;integer&quot;&gt;1&lt;/id&gt;\n    &lt;rating type=&quot;integer&quot;&gt;1&lt;/rating&gt;\n    &lt;name&gt;37signals&lt;/name&gt;\n    &lt;clients type=&quot;array&quot;&gt;\n      &lt;client&gt;\n        &lt;rating type=&quot;integer&quot;&gt;1&lt;/rating&gt;\n        &lt;name&gt;Summit&lt;/name&gt;\n      &lt;/client&gt;\n      &lt;client&gt;\n        &lt;rating type=&quot;integer&quot;&gt;1&lt;/rating&gt;\n        &lt;name&gt;Microsoft&lt;/name&gt;\n      &lt;/client&gt;\n    &lt;/clients&gt;\n    &lt;account&gt;\n      &lt;id type=&quot;integer&quot;&gt;1&lt;/id&gt;\n      &lt;credit-limit type=&quot;integer&quot;&gt;50&lt;/credit-limit&gt;\n    &lt;/account&gt;\n  &lt;/firm&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: To include any methods on the object(s) being called use :methods
- !ruby/struct:SM::Flow::VERB 
  body: "  firm.to_xml :methods =&gt; [ :calculated_earnings, :real_earnings ]\n\n  &lt;firm&gt;\n    # ... normal attributes as shown above ...\n    &lt;calculated-earnings&gt;100000000000000000&lt;/calculated-earnings&gt;\n    &lt;real-earnings&gt;5&lt;/real-earnings&gt;\n  &lt;/firm&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "To call any Proc's on the object(s) use :procs. The Proc's are passed a modified version of the options hash that was given to #to_xml."
- !ruby/struct:SM::Flow::VERB 
  body: "  proc = Proc.new { |options| options[:builder].tag!('abc', 'def') }\n  firm.to_xml :procs =&gt; [ proc ]\n\n  &lt;firm&gt;\n    # ... normal attributes as shown above ...\n    &lt;abc&gt;def&lt;/abc&gt;\n  &lt;/firm&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "Alternatively, you can also just yield the builder object as part of the to_xml call:"
- !ruby/struct:SM::Flow::VERB 
  body: "  firm.to_xml do |xml|\n    xml.creator do\n      xml.first_name &quot;David&quot;\n      xml.last_name &quot;Heinemeier Hansson&quot;\n    end\n  end\n\n  &lt;firm&gt;\n    # ... normal attributes as shown above ...\n    &lt;creator&gt;\n      &lt;first_name&gt;David&lt;/first_name&gt;\n      &lt;last_name&gt;Heinemeier Hansson&lt;/last_name&gt;\n    &lt;/creator&gt;\n  &lt;/firm&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: You can override the to_xml method in your ActiveRecord::Base subclasses if you need to. The general form of doing this is
- !ruby/struct:SM::Flow::VERB 
  body: "  class IHaveMyOwnXML &lt; ActiveRecord::Base\n    def to_xml(options = {})\n      options[:indent] ||= 2\n      xml = options[:builder] ||= Builder::XmlMarkup.new(:indent =&gt; options[:indent])\n      xml.instruct! unless options[:skip_instruct]\n      xml.level_one do\n        xml.tag!(:second_level, 'content')\n      end\n    end\n  end\n"
full_name: ActiveRecord::Serialization#to_xml
is_singleton: false
name: to_xml
params: (options = {}, &block)
visibility: public
