I have a WCF client that needs to generate a request containing this XML fragment :
<reason xsi:nil="true" nullFlavor="NA" typeCode="RSON" />
The schema is determined by the server and isn't under my control. The generated proxy code has a class for the reason element containing (among other things) properties nullFlavor
and typeCode
. The proxy uses the XmlSerializer.
How can I generate such a fragment? The XmlSerializer emits the xsi:nil
attribute only if the corresponding member is null. And if it's null, it can't very well have properties that will be emitted as attributes!
BTW, the fragment is legal according to the XML Schema Instance spec, which says a nil element cannot contain any child elements or inner text, but may contain attributes.