I can use [XmlIgnore] in order not to write elements, but how can I control this based on the content of a variable?
For example, I don't want to write XML element when the value is null.
[XmlRootAttribute("Component", IsNullable = true)]
public class Component {
[XmlArrayAttribute("worlds_wola", IsNullable = true)]
public List<Hello> worlds;
public int? a = null;
public int? b = null;
public Component()
{
worlds = new List<Hello>() {new Hello(), new Hello()};
}
}
However, I got this XML.
<worlds_wola>
...
</worlds_wola>
<a xsi:nil="true" />
<b xsi:nil="true" />
Is there any way not to get an element that doens't have any value such as "<a/>
" or "<b/>
"?