Is there a way to make the serialized member serialized as an attribute?

Is there a way to make the serialized member serialize as an attribute:

<Serializable> 
Public Class Person
    Public Property Name As String
End Class

      

I want that when this class is xml serialized it should produce:

<Person Name="John Doe" />

      

And what I mean is that instead of the Name property should be serialized as an element, it should be serialized as an xml attribute.

+2


a source to share


1 answer


I think you are looking for the XmlAttribute :

<Serializable()> 
Public Class Person
    <Xml.Serialization.XmlAttribute()> 
    Public Property Name() As String
End Class

      



More details and attributes of Xml serialization here .

+2


a source







All Articles