Excluding null values from ActiveRecord.to_xml

By default when you call to_xml on an ActiveRecord instance it will include all the null column in the table as empty xml nodes.

This poses a problem with the C# client app I'm trying to develop that consumes that xml. .Net's built in xml serializer doesn't handle empty nodes very well and actually throws an exception when it finds them. I'm not having any luck setting .net to ignore these empty nodes either...

A workaround to this, I imagine, would be to override to_xml to not include null fields in the xml response. Maybe a add a custom option like ...to_xml { exclude_null_fields => true }.

Can somebody give me some pointers on how to implement this?