Thursday, April 09, 2009

Character encoding in custom to_xml methods

I was writing some tests for my custom to_xml method on an ActiveRecord model and needed to check that the text had been escaped properly. to_xml changse lots of characters to XML entities and I couldn't find where that encoding happens. So I tossed a few exceptions into the xml serializer and found that the xml serializer calls to_xs on strings before including them in the xml. It's defined in:


So if you need to pattern match the output of your xml generator, you can call to_xs to get the text that it is going to output.

No comments: