假设我有以下类结构:
我创建了下面的结构:
当我将这个结构进行Xml序列化时,我得到以下输出:
[XmlInclude(typeof(CustomNode))]
[XmlInclude(typeof(CustomNode2))]
[XmlRoot("node")]
class Node
{
[XmlElement("node")]
public Node[] Children { get; set; }
}
[XmlRoot("custom-node")]
class CustomNode : Node { }
[XmlRoot("custom-node-2")]
class CustomNode2 : Node { }
我创建了下面的结构:
我创建了下面的结构:
var root = new Node { Children = new Node[2] };
root.Children[0] = new CustomNode();
root.Children[1] = new CustomNode2();
当我将这个结构进行Xml序列化时,我得到以下输出:
<node>
<node xsi:Type="CustomNode"/>
<node xsi:Type="CustomNode2"/>
</node>
但是我希望能够看到(并能够正确加载)类似于这样的内容:
<node>
<custom-node/>
<custom-node-2/>
</node>
对于XmlSerializer,是否有可能实现手动创建源xml并使其更具人性化和友好性?