What do you want the resulting XML to look like?  Usually XML has name/
value format.

You can do this:

class Symbol
  def to_xml
    {self => self.to_s}.to_xml
  end
end

and then you can call :hello.to_xml

=>   <hello>hello</hello>

That's a little dangerous, though, and it may turn out that you should
rethink the XML schema, and use hashes in general.

On Oct 6, 6:30 pm, Sam <[EMAIL PROTECTED]> wrote:
> Why is it that...
>
> {code}>> myarray = ["one"]
> => ["one"]
> >> myarray.to_xml
>
> RuntimeError: Not all elements respond to to_xml
>         from /foo/vendor/rails/activerecord/lib/../../activesupport/lib/
> active_support/core_ext/array/conversions.rb:62:in `to_xml'
>         from (irb):94
>
> {code}
>
> ... however ...
>
> {code}>> myarray2 = [{:one => "onevalue"}]
>
> => [{:one=>"onevalue"}]>> myarray2.to_xml
>
> => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<records type=\"array
> \">\n  <record>\n    <one>onevalue</one>\n  </record>\n</records>\n"
>
> {code}
>
> Is there a way I can convert an array to xml without having to wrap
> each element in a hash???
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to