IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Compléter mon fichier XML avec un flux serializer


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de llaffont
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Juin 2007
    Messages
    702
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Juin 2007
    Messages : 702
    Par défaut Compléter mon fichier XML avec un flux serializer
    Hello !

    J'ai créé dernièrement ces classes permettant de générer et de lire mon fichier XML.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
     
     
     
    using System.Xml.Serialization;
    using System.IO;
    using System;
     
     
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
    public partial class SerializeXML {
     
        private SerializeXMLElements[] itemsField;
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Elements", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public SerializeXMLElements[] Items {
            get {
                return this.itemsField;
            }
            set {
                this.itemsField = value;
            }
        }
    }
     
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    public partial class SerializeXMLElements {
     
        private int idField;
     
        private SerializeXMLElementsUC[] ucField;
     
        private SerializeXMLElementsECRAN[] eCRANField;
     
        private SerializeXMLElementsIMPRIMANTE[] iMPRIMANTEField;
     
        private SerializeXMLElementsOTHER[] oTHERField;
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public int ID
        {
            get
            {
                return this.idField;
            }
            set
            {
                this.idField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("UC", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public SerializeXMLElementsUC[] UC {
            get {
                return this.ucField;
            }
            set {
                this.ucField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("ECRAN", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public SerializeXMLElementsECRAN[] ECRAN {
            get {
                return this.eCRANField;
            }
            set {
                this.eCRANField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("IMPRIMANTE", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public SerializeXMLElementsIMPRIMANTE[] IMPRIMANTE {
            get {
                return this.iMPRIMANTEField;
            }
            set {
                this.iMPRIMANTEField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("OTHER", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public SerializeXMLElementsOTHER[] OTHER {
            get {
                return this.oTHERField;
            }
            set {
                this.oTHERField = value;
            }
        }
    }
     
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    public partial class SerializeXMLElementsUC {
     
        private string id_ucField;
     
        private string hostnameField;
     
        private string osField;
     
        private string n_osField;
     
        private string serv_packField;
     
        private string loginField;
     
        private string uc_snField;
     
        private string uc_constructField;
     
        private string uc_modelField;
     
        private string uc_inventaireField;
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string id_uc {
            get {
                return this.id_ucField;
            }
            set {
                this.id_ucField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string hostname {
            get {
                return this.hostnameField;
            }
            set {
                this.hostnameField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string os {
            get {
                return this.osField;
            }
            set {
                this.osField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string n_os {
            get {
                return this.n_osField;
            }
            set {
                this.n_osField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string serv_pack {
            get {
                return this.serv_packField;
            }
            set {
                this.serv_packField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string login {
            get {
                return this.loginField;
            }
            set {
                this.loginField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string uc_sn {
            get {
                return this.uc_snField;
            }
            set {
                this.uc_snField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string uc_construct {
            get {
                return this.uc_constructField;
            }
            set {
                this.uc_constructField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string uc_model {
            get {
                return this.uc_modelField;
            }
            set {
                this.uc_modelField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string uc_inventaire {
            get {
                return this.uc_inventaireField;
            }
            set {
                this.uc_inventaireField = value;
            }
        }
    }
     
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    public partial class SerializeXMLElementsECRAN {
     
        private string id_ecField;
     
        private string ec_snField;
     
        private string ec_constructField;
     
        private string ec_modelField;
     
        private string ec_sizeField;
     
        private string ec_inventaireField;
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string id_ec {
            get {
                return this.id_ecField;
            }
            set {
                this.id_ecField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string ec_sn {
            get {
                return this.ec_snField;
            }
            set {
                this.ec_snField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string ec_construct {
            get {
                return this.ec_constructField;
            }
            set {
                this.ec_constructField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string ec_model {
            get {
                return this.ec_modelField;
            }
            set {
                this.ec_modelField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string ec_size {
            get {
                return this.ec_sizeField;
            }
            set {
                this.ec_sizeField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string ec_inventaire {
            get {
                return this.ec_inventaireField;
            }
            set {
                this.ec_inventaireField = value;
            }
        }
    }
     
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    public partial class SerializeXMLElementsIMPRIMANTE {
     
        private string id_impField;
     
        private string imp_snField;
     
        private string imp_constructField;
     
        private string imp_modelField;
     
        private string imp_inventaireField;
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string id_imp {
            get {
                return this.id_impField;
            }
            set {
                this.id_impField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string imp_sn {
            get {
                return this.imp_snField;
            }
            set {
                this.imp_snField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string imp_construct {
            get {
                return this.imp_constructField;
            }
            set {
                this.imp_constructField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string imp_model {
            get {
                return this.imp_modelField;
            }
            set {
                this.imp_modelField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string imp_inventaire {
            get {
                return this.imp_inventaireField;
            }
            set {
                this.imp_inventaireField = value;
            }
        }
    }
     
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    public partial class SerializeXMLElementsOTHER {
     
        private string id_otherField;
     
        private string other_snField;
     
        private string other_constructField;
     
        private string other_modelField;
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string id_other {
            get {
                return this.id_otherField;
            }
            set {
                this.id_otherField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string other_sn {
            get {
                return this.other_snField;
            }
            set {
                this.other_snField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string other_construct {
            get {
                return this.other_constructField;
            }
            set {
                this.other_constructField = value;
            }
        }
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string other_model {
            get {
                return this.other_modelField;
            }
            set {
                this.other_modelField = value;
            }
        }
    }
     
     
    public class GestionFlux
    {
        public void write(string FileName,SerializeXML FluxXML)
        {
            XmlSerializer serialiser = new XmlSerializer(typeof(SerializeXML));
     
            if (File.Exists(FileName))
            {
                using (StreamWriter w = File.AppendText(FileName))
                {
                    serialiser.Serialize(w, FluxXML);
                    w.Close();
                }
            }
            else
            {
     
     
                TextWriter writer = new StreamWriter(FileName);
                serialiser.Serialize(writer, FluxXML);
                writer.Close();
            }
        }
     
     
        public SerializeXML read(string FileName)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(SerializeXML));
                serializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode);
                serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                FileStream fs = new FileStream(FileName, FileMode.Open);
                SerializeXML po = (SerializeXML)serializer.Deserialize(fs);
                return po;
            }
            catch { return null; }
     
        }
     
     
        protected void serializer_UnknownNode
       (object sender, XmlNodeEventArgs e)
        {
            System.Windows.Forms.MessageBox.Show("Unknown Node:" + e.Name + "\t" + e.Text);
        }
     
        protected void serializer_UnknownAttribute
        (object sender, XmlAttributeEventArgs e)
        {
            System.Xml.XmlAttribute attr = e.Attr;
            System.Windows.Forms.MessageBox.Show("Unknown attribute " +
            attr.Name + "='" + attr.Value + "'");
        }
     
     
    }
    Je coince aujourd'hui sur la manière de compléter mon fichier XML.
    Je pensais qu'il fallait lire le flux présent puis ajouter a sa suite les attributs XMLelement de mes classes.

    Mais a chaque fois il me complète le fichier XML avec une nouvelle racine XML.

    Je suis larguer. (Et je pense que mon explication n'est au top de clarté)

    donc pour être plus clair voilà mon fichier XML
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <?xml version="1.0" encoding="utf-8"?>
    <SerializeXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <Elements>
        <ID>1</ID>
        <UC>
          <id_uc />
          <hostname>STF01605</hostname>
          <os> Microsoft Windows XP Professionnel</os>
          <n_os></n_os>
          <serv_pack> Service Pack 3</serv_pack>
          <login> LLAFFONT</login>
          <uc_sn>45030650005</uc_sn>
          <uc_construct> MAXDATA</uc_construct>
          <uc_model>System Name</uc_model>
          <uc_inventaire>N° Inventaire : </uc_inventaire>
        </UC>
      </Elements>
    </SerializeXML><?xml version="1.0" encoding="utf-8"?>
    <SerializeXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <Elements>
        <ID>2</ID>
        <UC>
          <id_uc />
          <hostname>STF01605</hostname>
          <os> Microsoft Windows XP Professionnel</os>
          <n_os></n_os>
          <serv_pack> Service Pack 3</serv_pack>
          <login> LLAFFONT</login>
          <uc_sn>45030650005</uc_sn>
          <uc_construct> MAXDATA</uc_construct>
          <uc_model>System Name</uc_model>
          <uc_inventaire>N° Inventaire : </uc_inventaire>
        </UC>
      </Elements>
    </SerializeXML>
    Merci d'avance pour vos astuces.

  2. #2
    Membre expérimenté
    Avatar de StormimOn
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2005
    Messages
    2 593
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2005
    Messages : 2 593
    Par défaut
    Au moment de l'écriture tu fais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    if (File.Exists(FileName))
    {
        using (StreamWriter w = File.AppendText(FileName))
        {
            serialiser.Serialize(w, FluxXML);
            // Cette ligne est inutile. L'appel implicite à Dispose (bloc using) le fera
            // w.Close();
        }
    }
    Résultat tu écris à la fin du fichier existant.

    Pour compléter le fichier tu dois désérialiser pour obtenir les données contenues dans le fichier. Modifier les données ensuite. Et pour finir sérialiser les nouvelles données en écrasant le contenu du fichier.

  3. #3
    Membre éclairé Avatar de llaffont
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Juin 2007
    Messages
    702
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Juin 2007
    Messages : 702
    Par défaut
    Merci pour la correction.

    J'avais peur que la solution soit celle là...
    Je vais tenter la dé-sérialisation puis l'écrasement.

    Puis je reviens vers vous pour vous tenir informés.

  4. #4
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    La sérialisation XML écrit toujours un document XML complet. Pour pouvoir ajouter des éléments à ton fichier, il faudrait les ajouter avant la balise de fin de document, mais il n'est pas possible d'insérer du texte en milieu de fichier, seulement à la fin.

    La solution, à mon avis, est de :
    - désérialiser le fichier existant pour obtenir un objet SerializeXML
    - ajouter les nouveaux éléments à la collection Items (d'ailleurs il faudrait que ce soit une List<SerializeXMLElements> plutôt qu'un tableau, de façon à pouvoir ajouter ou supprimer des élements).
    - réécrire l'objet SerializeXML en entier dans le fichier

  5. #5
    Membre éclairé Avatar de llaffont
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Juin 2007
    Messages
    702
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Juin 2007
    Messages : 702
    Par défaut
    J'ai l'impression de m'être lancé dans un truc un peu trop compliqué pour moi

    On est d'accord que c'est ce petit bout de code qu'il fallait passer le Tableau à List<t>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    public partial class SerializeXML {
     
        private List<SerializeXMLElements> itemsField;
     
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Elements", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public List<SerializeXMLElements> Items
        {
            get {
                return this.itemsField;
            }
            set {
                this.itemsField = value;
            }
        }
    }
    Pour ensuite modifier dans ma fonction qui récupère les différentes informations saisies.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
     SerializeXML InventaireXML;
                InventaireXML = new SerializeXML();
                SerializeXMLElements Root = new SerializeXMLElements();
     
                SerializeXMLElementsUC UC_ROOT = new SerializeXMLElementsUC();            
                UC_ROOT.id_uc = "";
                UC_ROOT.hostname = lbl_MachineName_Result.Text.ToString();
                UC_ROOT.login = tbx_Login.Text.ToString();
                UC_ROOT.n_os = lbl_SN_Os_Result.Text.ToString();
                UC_ROOT.os = lbl_Os_Result.Text.ToString();
                UC_ROOT.serv_pack  = lbl_SP_Result.Text.ToString();
                UC_ROOT.uc_construct = lbl_Constru_Result.Text.ToString();
                UC_ROOT.uc_inventaire = lbl_Inventaire.Text.ToString();
                UC_ROOT.uc_model = lbl_Model_Result.Text.ToString();
                UC_ROOT.uc_sn = lbl_SN_Result.Text.ToString();
     
                SerializeXMLElementsUC[] Tab_UC_ROOT = { UC_ROOT };
                Root.UC = Tab_UC_ROOT;
     
    [...]
     
    InventaireXML.Items.Add(Root);

    ça me retourne une erreur
    La référence d'objet n'est pas définie à une instance d'un objet.
    J'y perds mon peu de Latin

  6. #6
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Le champ itemsField n'est pas initialisé. Initialise le dans le constructeur de la classe SerializeXML

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 15/04/2014, 14h58
  2. Réponses: 6
    Dernier message: 24/03/2010, 16h31
  3. [AJAX] réinitialiser mon fichier xml avec IE
    Par aztec dans le forum AJAX
    Réponses: 1
    Dernier message: 14/12/2009, 08h57
  4. [DTD] Valider mon fichier xml gràce à ma DTD avec DOM
    Par fonkyom dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 09/02/2008, 13h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo