Bonjour j'ai un gros problème je commence tous juste en XML avec C# voici ce que j'ai fait:

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Serialization;
 
 
 
namespace xml
{
 
    namespace Xml2CSharp
    {
 
 
        [XmlRoot(ElementName = "BARCODES")]
        public class BARCODES
        {
 
 
            [XmlElement(ElementName = "BARCODE")]
            public List<string> BARCODE { get; set; }
        };
 
        [XmlRoot(ElementName = "SORTED")]
        public class SORTED
        {
            [XmlElement(ElementName = "SORT_NUMBER")]
            public string SORT_NUMBER { get; set; }
            [XmlElement(ElementName = "HEIGHT")]
            public string HEIGHT { get; set; }
            [XmlElement(ElementName = "LOGICAL_SORTING")]
            public string LOGICAL_SORTING { get; set; }
        };
 
        [XmlRoot(ElementName = "CONTAINER")]
        public class CONTAINER
        {
            [XmlElement(ElementName = "BARCODES")]
            public BARCODES BARCODES { get; set; }
            [XmlElement(ElementName = "SORTED")]
            public SORTED SORTED { get; set; }
            [XmlAttribute(AttributeName = "containerId")]
            public string ContainerId { get; set; }
            [XmlAttribute(AttributeName = "site")]
            public string Site { get; set; }
            [XmlAttribute(AttributeName = "siteNum")]
            public string SiteNum { get; set; }
            [XmlAttribute(AttributeName = "status")]
            public string Status { get; set; }
            [XmlAttribute(AttributeName = "containerType")]
            public string ContainerType { get; set; }
            [XmlAttribute(AttributeName = "wmsContainerId")]
            public string WmsContainerId { get; set; }
        };
 
        [XmlRoot(ElementName = "CONTAINER_REPORT")]
        public class CONTAINER_REPORT
        {
            [XmlElement(ElementName = "CONTAINER")]
            public CONTAINER CONTAINER { get; set; }
            [XmlAttribute(AttributeName = "reportId")]
            public string ReportId { get; set; }
            [XmlAttribute(AttributeName = "date")]
            public string Date { get; set; }
        };
 
        [XmlRoot(ElementName = "WCS")]
        public class WCS
        {
            [XmlElement(ElementName = "CONTAINER_REPORT")]
            public CONTAINER_REPORT CONTAINER_REPORT { get; set; }
            [XmlAttribute(AttributeName = "reference")]
            public string Reference { get; set; }
 
 
 
            internal static void Save(string p)
            {
                throw new NotImplementedException();
            }
        };
 
    }
 
 
 
 
 
}
le code au dessus c'est ce que je veut sérialiser.


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
using System.IO;
using System.Xml;
using System.Xml.Serialization;
 
 
 
namespace ConsoleApplication4
{
    public class Program
    {
        static void Main(string[] args)
        {
            string readText = "<myxml></myxml>";
            //récuperer fichier xml 
            //passer de XML à un objet 
            xml.Xml2CSharp.WCS toto = new xml.Xml2CSharp.WCS();
            string path = @"C:\Users\beils\Desktop\test\data.xml";
 
 
 
            // This text is added only once to the file.
            if (!File.Exists(path))
            {
                readText = File.ReadAllText(path);
            }
 
            // Open the file to read from.           
            XmlDocument xdoc = new XmlDocument();
            xdoc.LoadXml(readText);
            // If xml coming via some other datasource, create a corresponding reader
 
            XmlSerializer xs = new XmlSerializer(typeof(xml.Xml2CSharp.WCS));
 
            using (StreamWriter wr = new StreamWriter(@"C:\Users\beils\Desktop\test\test.xml"))
 
            {
                xs.Serialize(wr, toto);
            }
 
 
 
        }
 
 
 
 
    }
}
Sa c'est le code que j'ai utiliser.



Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
<?xml version="1.0" encoding="utf-8"?>
<WCS xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
Voici se que j'obtient sur google.

J'aimerais arriver à sérialiser:
BARCODES, SORTED, CONTAINER, CONTAINER_REPORT et WCS mais je n'arrive pas a trouver comment j'ai rechercher sur des forums mais je n'est jamais trouver le bon code,
et puis aussi je pense qu'il faut que je me m'améliore en recherche.
Je ne vois pas ou est mon erreur.

Merci d'avance.
Cordialement lejeunedefrance