Question: I want to serialize an object where some of the member variables are of type `string` and have the value `null`.
I use the following code:

```
        var writer = new XmlTextWriter(stream, Encoding.UTF8);
        writer.Formatting = Formatting.Indented;

        var s = new XmlSerializer(typeof(model.GetType()));            
        s.Serialize(writer, model);

```

The strings with value `null` don't appear in the Xml file (which is obviously intended behavior), although I don't want that. 
How can I make `null` strings appear in the Xml file by overriding the `XmlTextWriter` class?

EDIT: I can't modify the object model that needs to be serialized, so Xml attributes are no option.

Answer: 
You could use:

```
[XmlElement(IsNullable = true)]

```

on any member you want to be written on file even if null.
you can use this attribute on you member : 

```
[XmlElement(IsNullable = true)]

```

it will set an attribute on your element specifying that it is null instead of not serializing it.