xml的xsi:type序列化和反序列化

最近在做HL7V3的对接,关于XML的序列化和反序列化遇到xsi:type的问题解决方法

实体类定义:

复制代码
public class HL7V3_ProviderOrganization
{
    public HL7V3_Name Name { get; set; }
}
public class Bomb : HL7V3_Name
{

}
[XmlInclude(typeof(Bomb))]
public class HL7V3_Name
{
    [XmlElement]
    public HL7V3_Name_Item Item { get; set; }
}
public class HL7V3_Name_Item
{
    [XmlElement]
    public HL7V3_Ele_Value Part { get; set; }
}
public class HL7V3_Ele_Value
{
    [XmlAttribute]
    public string Value { get; set; }
}
复制代码

XML序列化:

复制代码
var s = new HL7V3_ProviderOrganization()
{
    Name = new Bomb()
    {
        Item = new HL7V3_Name_Item()
        {
            Part = new HL7V3_Ele_Value()
            {
                Value = "surprise motherfucker!"
            }
        }
    }
}.ToXml();
复制代码

XML生成:

具体可参考:https://docs.microsoft.com/en-us/dotnet/standard/serialization/controlling-xml-serialization-using-attributes

 

 

出处:https://www.cnblogs.com/Little-Wang/p/8784534.html

================================================================

 参考文章:

在XML序列化时,如何设置xsi:type ?

posted on 2019-12-27 16:57  jack_Meng  阅读(1673)  评论(0编辑  收藏  举报

导航