According to W3C standards, if you have a nillable element with a nil value, you are supposed to format it like this:
You could also do something like this, taking advantage of the null coalescing operator:
public static object Nil
{
get
{
// **I took a guess at the syntax here - you should double check.**
return new XAttribute(Xsi + "nil", true);
}
}
// ......
object nullableContent = ...;
element.Add(
new XElement(NS + "myNillableElement", nullableContent ?? Nil)
);