deltu100
deltu100

Reputation: 581

how do I serialize the following format?

I am wondering how to get the following format on a single property including a type. Like so:

**<Productname type ="Drinks">coke<Productname>** 

What have I tried?

<XmlRoot("Productname1")> _
Public Class Productname
<XmlAttribute("Type")> Public type As String = "Drinks"


Private m_Productname As String
Public Property Productname() As String
    Get
        Return m_Productname
    End Get
    Set(ByVal value As String)
        m_Productname = value
    End Set
End Property
End Class

but the following will happen with my code

  <Productname1 Type="Drinks">
  <Productname >coke</Productname > 
  </Productname1>

I just don't understand how this works and I have been searching for a while now.

Upvotes: 1

Views: 44

Answers (1)

WozzeC
WozzeC

Reputation: 2660

Try this, it should work.

   Public Class ProductName
        <XmlAttribute("Type")>
        Property type As String = "Drinks"
        <XmlText()>
        Property Text As String = "Coke"
    End Class

Upvotes: 1

Related Questions