J'ai utilisé la sérialisation XML pendant un moment, et aujourd'hui j'ai réalisé quelque chose de vraiment bizarre. Si j'ai une nouvelle ligne juste après un "point" (.), Quand je désérialise, je perds le point. Est-ce que quelqu'un a déjà eu cela? Ce qui suit est mon code de sérialisation:Sérialisation VB.NET Point manquant juste avant la sérialisation de la nouvelle ligne
sérialisation
Dim xmlSerializer As New System.Xml.Serialization.XmlSerializer(GetType(SilverWare.Licensing.Common.StoreLicense), New System.Type() {GetType(SilverWare.Licensing.Common.StationLicense)})
Dim gen As LicenseGenerator
If store Is Nothing Then
Throw New ArgumentNullException("store")
ElseIf store.StationLicenses Is Nothing Then
Throw New ArgumentNullException("store.StationLicenses")
ElseIf store.StationLicenses.Length = 0 Then
Throw New ArgumentOutOfRangeException("store.StationLicenses", "Must contain at least one element.")
End If
' Create a license generator for issuing new license keys.
gen = New LicenseGenerator(store)
' Generate store key.
store.LicenseKey = gen.GenerateLicenseKey
' Generate individual station keys.
For Each station In store.StationLicenses
station.LicenseKey = gen.GenerateLicenseKey(station)
Next
' Write license to file.
Using xFile As Xml.XmlWriter = Xml.XmlWriter.Create(licenseFile)
xmlSerializer.Serialize(xFile, store)
xFile.Close()
End Using
Deserialize
Dim xmlDeserializer As New System.Xml.Serialization.XmlSerializer(GetType(SilverWare.Licensing.Common.StoreLicense), New System.Type() {GetType(SilverWare.Licensing.Common.StationLicense)})
Dim result As SilverWare.Licensing.Common.StoreLicense
Using xFile As Xml.XmlReader = Xml.XmlReader.Create(licenseFile)
result = DirectCast(xmlDeserializer.Deserialize(xFile), SilverWare.Licensing.Common.StoreLicense)
xFile.Close()
End Using
Return result
La partie vraiment drôle est que si j'ai un espace après le point, ou supprimer la nouvelle caractère de ligne, il n'y a pas de problèmes. Cela n'arrive que si c'est un point que je trouve ahurissant.
Voici un exemple rapide de mon fichier XML qui a été créé quand je sérialisé:
<?xml version="1.0" encoding="utf-8" ?>
<StoreLicense xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
...
<ReceiptAddress>98 N. Washington St.
Berkeley Springs West Virginia</ReceiptAddress>
<Name>Ambrae House at Berkeley Springs</Name>
<AliasName>Ambrae House</AliasName>
<Address1>98 N. Washington St.</Address1>
<Address2 />
...
</StoreLicense>
La ligne qui a le problème est le nœud ReceiptAddress.
Où est ce point et nouvelle ligne? –
Le point et la nouvelle ligne sont dans le fichier en sortie. Fondamentalement, j'ai un objet qui est sérialisable. Cet objet contient un tas de chaînes, et une de ces chaînes contient quelque chose comme: 234, rue Gor Toronto, Ontario Notez le point après st. Cela disparaîtra quand je désérialiserai. Quand je regarde le fichier xml sorti, le point et la nouvelle ligne semblent bien. C'est seulement pendant la désérialisation que je perds le point. – JohnathanKong
@Mattias a raison. Pouvez-vous nous donner un exemple rapide d'entrée et de sortie, s'il vous plaît? – Rap