我正面临一个小问题,并尝试了一些推荐的解决方案,但由于某些原因我没有为我工作。
我的一个元素是在序列化时保留“_”。对我可能缺少什么的想法?
Imports System.Xml.Serialization
Public Class AddressBook
Private _AddressEntries As New List(Of AddressBookEntry)
Public _AddressGroups As New List(Of AddressBookGroup)
<XmlElement(ElementName:="AddressEntries")> _
Public Property AddressEntries As List(Of AddressBookEntry)
Get
Return _AddressEntries
End Get
Set(value As List(Of AddressBookEntry))
_AddressEntries = value
End Set
End Property
<XmlElement(ElementName:="AddressGroups")> _
Public Property AddressGroups As List(Of AddressBookGroup)
Get
Return _AddressGroups
End Get
Set(value As List(Of AddressBookGroup))
_AddressGroups = value
End Set
End Property
End Class
Public Class AddressBookEntry
Private _Country As String
Private _AddressGroup As AddressBookGroup
Private _IPAddress As String
Private _Name As String
Private _StoreNumber As String
Public Property Country As String
Get
Return _Country
End Get
Set(value As String)
_Country = value.ToString.ToUpper
End Set
End Property
Public Property AddressGroup As AddressBookGroup
Get
Return _AddressGroup
End Get
Set(value As AddressBookGroup)
_AddressGroup = value
End Set
End Property
Public Property IPAddress As String
Get
Return _IPAddress
End Get
Set(value As String)
_IPAddress = value
End Set
End Property
Public Property Name As String
Get
Return _Name
End Get
Set(value As String)
_Name = value
End Set
End Property
Public Property StoreNumber As String
Get
Return _StoreNumber
End Get
Set(value As String)
_StoreNumber = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(AddressGroup As AddressBookGroup,
IPAddress As String,
Name As String,
StoreNumber As String)
Me._AddressGroup = AddressGroup
Me._IPAddress = IPAddress
Me._Name = Name
Me._StoreNumber = StoreNumber
End Sub
End Class
Public Class AddressBookGroup
Private _Name As String
Public Property Name As String
Get
Return _Name
End Get
Set(value As String)
_Name = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(GroupName As String)
Me._Name = GroupName
End Sub
End Class
输出如下所示,而不是AddressGroups元素中的'_'?
<AddressBook xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<_AddressGroups>
<AddressBookGroup>
<Name>None</Name>
</AddressBookGroup>
</_AddressGroups>
<AddressEntries>
<AddressGroup>
<Name>None</Name>
</AddressGroup>
<IPAddress>a.b.c.d</IPAddress>
<Name>MyName</Name>
<StoreNumber>MyNumber</StoreNumber>
</AddressEntries>
<AddressGroups>
<Name>None</Name>
</AddressGroups>
</AddressBook>
答案 0 :(得分:0)
我有公开声明而不是私人声明。