为什么我在序列化XML中得到这个结果 [英] why i get this result in the serialization XML

查看:59
本文介绍了为什么我在序列化XML中得到这个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i进行了类的序列化,我得到了这个结果:



Hi,
i made the serialization of a class and i get this result:

<?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>



为什么de DateData如下所示:

0001-01-01T00:00:00

通常我需要这样的日期dd / mm / yy



最后,我想知道为什么我有:



xmlns:xsd =http://www.w3.org/2001/XMLSchemaxmlns :的xsi =HTTP://www.w3.or g / 2001 / XMLSchema-instance



谢谢



来自评论的复制代码




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

Copied code from comment

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





[/ EDIT]



[/EDIT]

推荐答案

日期以特殊的文化中立和最方便的格式呈现,使用所谓的往返格式说明符:

http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#Roundtrip [ ^ ]。



而你的dd / mm / yy通常没有好处,只是模棱两可。考虑11/12/13。它可能是2013年11月12日,但可能是2013年12月11日。你怎么知道它是2013年,而不是1913年?请不要告诉我这应该只是2013年11月12日。不同。不同的人(和不同的人)使用不同的文化。



如果您需要在某些应用程序或某些设置中格式化某些文化的日期/时间,请使用这个:

http://msdn.microsoft.com/en-us/ library / ht77y576.aspx [ ^ ]。



或者这个:

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

http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx [ ^ ]。



参见:

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



或者,您可以更改线程的文化,因此所呈现日期/时间的默认文化将相应更改:

< a href =http://msdn.microsoft.com/en-us/library/system.threading.thread.currentculture.aspx> 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
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


这篇关于为什么我在序列化XML中得到这个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆