VB.NET or C# XML Serialization/Deserialization Order attribute



Trying to serialize/deserialize an object in a specific order by setting but the order never works. The XML is always serialized in alphabetical order. Here is the class I am using.



<XmlElement(Order:=1)>
Public Property ChkNum() As String
Get
Return Me.chkNumField
End Get
Set(value As String)
Me.chkNumField = value
End Set
End Property

'''<remarks/>
<XmlElement(Order:=2)>
Public Property AcctId() As String
Get
Return Me.acctIdField
End Get
Set(value As String)
Me.acctIdField = value
End Set
End Property

'''<remarks/>
<XmlElement(Order:=3)>
Public Property TranCode() As String
Get
Return Me.tranCodeField
End Get
Set(value As String)
Me.tranCodeField = value
End Set
End Property

'''<remarks/>
''<System.Xml.Serialization.XmlElement("TranAmt", Order:=4)>
<XmlElement(Order:=4)>
Public Property CurAmt() As CurAmt_Type
Get
Return Me.curAmtField
End Get
Set(value As CurAmt_Type)
Me.curAmtField = value
End Set
End Property


My code looks like this Dim chkDat(1) As ChkData_Type chkDat(0) = New ChkData_Type chkDat(0).ChkNum = "00FF" chkDat(0).AcctId = "1000122703" chkDat(0).TranCode = "999" chkDat(0).CurAmt = New CurAmt_Type chkDat(0).CurAmt.Amt = "250.00"


The result after serialization comes in the below order AcctID,ChkNum,CurAmt and TranCode.


I have seen Order attribute working for others. Not sure what is wrong with the above code. Any help would be greatly appreicated.


No comments:

Post a Comment