У меня есть список базовых классов
Public Class Package
<XmlElement("OBJECT")>
Public List As List(Of baseobj)
Public Sub New()
List = New List(Of baseobj)
Dim f As New First()
Dim s As New Second()
List.Add(s)
List.Add(f)
End Sub
Function Serialize() As String
Dim XmlSerializer As New XmlSerializer(GetType(Package), "")
Dim NS As New XmlSerializerNamespaces()
Dim SB As New StringBuilder
Dim str As New StringWriter(SB)
NS.Add("", "")
XmlSerializer.Serialize(str, Me, NS)
Return SB.ToString
End Function
End Class
Базовый класс
<XmlInclude(GetType(First))>
<XmlInclude(GetType(Second))>
Public MustInherit Class baseobj
Public Common As String
Public Sub New()
Common = "_Common"
End Sub
End Class
И водил классы
Public Class First
Inherits baseobj
<XmlAttribute("term")>
Public FirstAttr As String
Public Sub New()
MyBase.New()
FirstAttr = "FirstAttr"
End Sub
End Class
Public Class Second
Inherits baseobj
<XmlAttribute("term")>
Public SecAttr As String
Public Sub New()
MyBase.New()
SecAttr = "SecAttr"
End Sub
End Class
При сериализации объекта пакета (pkg.Serialize) есть это:
<?xml version="1.0" encoding="utf-16"?>
<Package>
<OBJECT d2p1:type="Second" term="SecAttr" xmlns:d2p1="http://www.w3.org/2001/XMLSchema-instance">
<Common>_Common</Common>
</OBJECT>
<OBJECT d2p1:type="First" term="FirstAttr" xmlns:d2p1="http://www.w3.org/2001/XMLSchema-instance">
<Common>_Common</Common>
</OBJECT>
</Package>
Как я могу сериализовать объект пакета в
<?xml version="1.0" encoding="utf-16"?>
<Package>
<OBJECT Type="Second" term="SecAttr" >
<Common>_Common</Common>
</OBJECT>
<OBJECT Type="First" term="FirstAttr">
<Common>_Common</Common>
</OBJECT>
</Package>
без пространств имен и префиксов