2013-01-18 1 views
1

형식을 포함하여 단일 속성에서 다음 형식을 얻는 방법을 궁금합니다. 좋아요 :다음 형식을 어떻게 serialize합니까?

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

무엇을 시도 했습니까?

<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 

하지만 다음은 내 코드

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

난 그냥이 작품과 내가 지금 잠시 동안 검색 한 방법을 이해하지 않습니다와 함께 발생합니다.

답변

1

시도해보십시오. 작동해야합니다.

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

답장을 보내 주셔서 감사합니다. 이것은 내가 찾고 있었던 바로 그 것이었다. 텍스트로도 이와 같이 작동 할 수 있는지 몰랐습니다. – deltu100

관련 문제