You want you to want this:
<parent> <child1>Hello World</child1> <child2 /> </parent>
instead
<parent> <child1>Hello World</child1> </parent>
your class should look like this: A serializer calls the ShouldSerializePropertyName method by definition (if one exists) to determine if a property should be serialized (for example, Windows Forms Designer).
public class Parent { [XmlElement("Child1")] public string Child1 { get; set; } [XmlElement("Child2")] public string Child2 { get; set; } public bool ShouldSerializeChild2() { return true; } }
Jürgen steinblock
source share