Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
i made the serialization of a class and i get this result:

XML
<?xml version="1.0" encoding="UTF-8"?>
-<AuditLogiciel Dates="0001-01-01T00:00:00" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><DateData>0001-01-01T00:00:00</DateData></AuditLogiciel>

Why de DateData is like this:
0001-01-01T00:00:00
Normally i need the date like this dd/mm/yy

And finally, i want to know why i have :

xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Thanks

[EDIT] Copied code from comment

VB
Imports System.Xml.Serialization
'<XmlRoot("AuditLogiciel")> 
<serializable()>
Public Class DataAcquisition
    Public Sub New()
        ' Rien à faire.
    End Sub
#Region "Déclaration"
    Public DateData As Date
    Public MesureCapteur As String

#End Region

#Region "Propiétés"
     '<XmlAttribute("Dates")>
    Public Property Dates() As Date
        Get
            Return DateData
        End Get
        Set(ByVal value As Date)
            DateData = value

        End Set
    End Property
    ' <XmlAttribute("CapteurMesure")>
    Public Property CapteurMesure() As String
        Get
            Return MesureCapteur
        End Get
        Set(ByVal value As String)
            MesureCapteur = value

        End Set
    End Property

#End Region

#Region "Métodes"
   
#End Region


End Class


In the main i have:
VB
Private Sub MainWindow_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing


    Dim xSerializer As XmlSerializer = New XmlSerializer(GetType(DataAcquisition))
    Dim writer As TextWriter = New StreamWriter("nomFichierConfigXml.XML")
    xSerializer.Serialize(writer, Config)
    writer.Close()

End Sub


[/EDIT]
Posted
Updated 18-Sep-13 6:10am
v2
Comments
phil.o 18-Sep-13 11:42am    
Moreover, how come you expect that we can tell you why you get this result if you do not post the code that produces it at first place?
alonetmr 18-Sep-13 11:52am    
Hi, here is the code

Imports System.Xml.Serialization
'<XmlRoot("AuditLogiciel")>
<serializable()>
Public Class DataAcquisition
Public Sub New()
' Rien à faire.
End Sub
#Region "Déclaration"
Public DateData As Date
Public MesureCapteur As String

#End Region

#Region "Propiétés"

'<XmlAttribute("Dates")>
Public Property Dates() As Date
Get
Return DateData
End Get
Set(ByVal value As Date)
DateData = value

End Set
End Property
' <XmlAttribute("CapteurMesure")>
Public Property CapteurMesure() As String
Get
Return MesureCapteur
End Get
Set(ByVal value As String)
MesureCapteur = value

End Set
End Property

#End Region

#Region "Métodes"


#End Region


End Class

In the main i have:

Private Sub MainWindow_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing


Dim xSerializer As XmlSerializer = New XmlSerializer(GetType(DataAcquisition))
Dim writer As TextWriter = New StreamWriter("nomFichierConfigXml.XML")
xSerializer.Serialize(writer, Config)
writer.Close()

End Sub

1 solution

The date is presented in the special culture-neutral and most convenient format using so called "round-trip" format specifier:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#Roundtrip[^].

And your "dd/mm/yy" is no generally no good and is simply ambiguous. Consider "11/12/13". It could be November 12, 2013, but it could be December 11, 2013. And how do you know it's 2013, not 1913? And please don't tell me this should be only "November 12, 2013". No. Different peoples (and different people) use different cultures.

If you need to format your date/time for certain culture in certain application or with certain settings, use this:
http://msdn.microsoft.com/en-us/library/ht77y576.aspx[^].

Or this:
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx[^].

See also:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^].

Alternatively, you can change the culture of your thread, so the default culture of the presented date/time will be changed accordingly:
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentculture.aspx[^],
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture.aspx[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900