John
John

Reputation: 1922

Can the XML serializer output empty tags?

I am using the XML serializer. I would like it to convert all my object's elements, but it only seems to output tags when there is a value.

How can I get it to output empty tags?

Upvotes: 4

Views: 4866

Answers (2)

Wagner Silveira
Wagner Silveira

Reputation: 1626

Take a look at a couple of options on how to solve this problem here:

http://danshultz.blogspot.com/2008/02/xmlserialization-nullempty-elements.html

Upvotes: 6

Marc Gravell
Marc Gravell

Reputation: 1062865

If I understand correctly, then not without implementing IXmlSerializable (which is not fun; don't go there). There are things like the ShouldSerialize* / *Specified patterns, but it still won't write something for nulls (even if you return true).

Upvotes: 1

Related Questions