# To\_xml follows different path for collections than for individual objects

**URL:** <https://www.ruby-forum.com/t/to-xml-follows-different-path-for-collections-than-for-individual-objects/119622>\
**Category:** Rails\
**Created:** [November 8, 2007, 4:34pm UTC](https://www.ruby-forum.com/t/to-xml-follows-different-path-for-collections-than-for-individual-objects/119622 "2007-11-08T16:34:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thanatos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8e8cbc/32.png) [@thanatos](https://www.ruby-forum.com/u/thanatos)\
**Post date:** [November 8, 2007, 4:34pm UTC](https://www.ruby-forum.com/t/to-xml-follows-different-path-for-collections-than-for-individual-objects/119622/1 "2007-11-08T16:34:33Z")

</div>

For example:

I have an item  
and in script/console of my project I do:

item.to\_xml

This executes through an elaborate path of modules and methods  
something like this:

```
 to_xml --> XmlSerializer --> which calls to_s, which is

```

an alias in xml\_serialization.rb for the method serialize. Serialize  
calls a method “builder” to make a new Builder::XmlMarkup (which  
extends from XmlBase). With this, the builder tags the attributes  
as needed.

However, if I try it with an array of items I can’t figure out where  
it goes to and in what order.

By putting out little notices in the different methods I mentioned  
above it would seem that to\_xml with a collection goes in a nearly  
reverse order from a single item.

The purpose of all of this is an attempt to add on option for to\_xml  
that would allow it to skip escaping the xml unicode into html  
entities (using \_escape --\> Xchar#to\_xs).

Thanks for any hints. It would be nice to learn how to actually debug  
something like this.

---

<div class="post-metadata">

**Author:** ![thanatos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8e8cbc/32.png) [@thanatos](https://www.ruby-forum.com/u/thanatos)\
**Post date:** [November 8, 2007, 4:38pm UTC](https://www.ruby-forum.com/t/to-xml-follows-different-path-for-collections-than-for-individual-objects/119622/2 "2007-11-08T16:38:39Z")

</div>

On 8 Nov 2007, at 15:33, thanatos wrote:

> However, if I try it with an array of items I can’t figure out where  
> it goes to and in what order.
> 
> By putting out little notices in the different methods I mentioned  
> above it would seem that to\_xml with a collection goes in a nearly  
> reverse order from a single item.

check out to\_xml in activesupport/lib/active\_support/core\_ext/array/  
conversions.rb

> The purpose of all of this is an attempt to add on option for to\_xml  
> that would allow it to skip escaping the xml unicode into html  
> entities (using \_escape --\> Xchar#to\_xs).
> 
> Thanks for any hints. It would be nice to learn how to actually debug  
> something like this.

step through it with rdebug ?

Fred
