# Excluding null values from ActiveRecord.to\_xml

**URL:** <https://www.ruby-forum.com/t/excluding-null-values-from-activerecord-to-xml/116162>\
**Category:** Rails\
**Created:** [October 3, 2007, 2:13am UTC](https://www.ruby-forum.com/t/excluding-null-values-from-activerecord-to-xml/116162 "2007-10-03T02:13:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [October 3, 2007, 2:13am UTC](https://www.ruby-forum.com/t/excluding-null-values-from-activerecord-to-xml/116162/1 "2007-10-03T02:13:34Z")

</div>

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?
