# Inconsistency in calling to\_xml on STI returning \<record\>

**URL:** <https://www.ruby-forum.com/t/inconsistency-in-calling-to-xml-on-sti-returning-record/151288>\
**Category:** Rails\
**Created:** [October 19, 2008, 9:48pm UTC](https://www.ruby-forum.com/t/inconsistency-in-calling-to-xml-on-sti-returning-record/151288 "2008-10-19T21:48:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhao\_Lu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/58956e/32.png) [@Zhao\_Lu](https://www.ruby-forum.com/u/Zhao_Lu)\
**Post date:** [October 19, 2008, 9:48pm UTC](https://www.ruby-forum.com/t/inconsistency-in-calling-to-xml-on-sti-returning-record/151288/1 "2008-10-19T21:48:50Z")

</div>

Hi,

When calling to\_xml on STI that returns heterogeneous type of records,  
each record is contained in node.  
For example, if I have Account with subclasses EmailAccount and  
PhoneAccount, Account.find(:all).to\_xml gives me:  
  
\<emailaddress1 …\>  
  
  
\<phonenumber1…\>

When calling to\_xml on homogeneous type of records, each record is  
contained in the node with the type.  
For example, Account.find(:all, :conditions=\>{:type =\> ‘PhoneAccount’})  
\<phone\_account\>  
\<phonenumber1…\>  
\</phone\_account\>

I feel this makes writing test and client-side parsing difficult. I  
did some search and didn’t find anything solutions (except a trac  
ticket opened over a year ago with status open). I also feel this is  
probably a often-encountered issue and have some  
pragmatic solution. Any suggestion is appreciated.

Thanks,

–  
Zhao
