Bonjour,

J'ai du xml dans une colonne de ma table sql server et jarrive à récupérer certaines infos de cette colonne.

Je n'arrive pas à récupérer la valeur des champs contact_companyname et contact_siret. Pour le reste j'y arrive. Pouvez vous m'aider à trouver la solution. Ci-dessous mon code C# et la colonne XML.

Merci pour votre aide.

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
 
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Xml;
using System.Linq;
using System.Xml.Linq;
using System.Globalization;
using System.Threading;
using System.Text;
 
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
 
    public override void PreExecute()
    {
        base.PreExecute();
        /*
          Add your code here for preprocessing or remove if not needed
        */
    }
 
    public override void PostExecute()
    {
        base.PostExecute();
        /*
          Add your code here for postprocessing or remove if not needed
          You can set read/write variables here, for example:
          Variables.MyIntVar = 100
        */
    }
 
    public override void Entrée0_ProcessInputRow(Entrée0Buffer Row)
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR");
        /*
          Add your code here
        */
 
        XmlDocument xml = new XmlDocument();
        string x = System.Text.Encoding.GetEncoding(1252).GetString(Row.DMESSAGEDETAILS.GetBlobData(0, (int)Row.DMESSAGEDETAILS.Length));
 
        if (x.Contains("(<DateEmission>"))
            System.Windows.Forms.MessageBox.Show(x);
 
 
        XDocument doc = XDocument.Parse(x);
        var reqs = from Donnees in doc.Descendants("Donnees")         
 
           select new
                       {
                           IdentifiantUnique = Donnees.Element("IdentifiantUnique") == null ? "" : Donnees.Element("IdentifiantUnique").Value,
                           CodeProcessus = Donnees.Element("CodeProcessus") == null ? "" : Donnees.Element("CodeProcessus").Value,
                       };
 
        try
        {
            foreach (var req in reqs)
            {
                //test affichage noeud
                //System.Windows.Forms.MessageBox.Show(xml.SelectSingleNode("(/Alerte/Donnees/IdentifiantUnique/text())[1]").Value.ToString());
                Row.IdentifiantUnique = req.IdentifiantUnique.Trim();
                Row.CodeProcessus = req.CodeProcessus.Trim();
            }
        }
 
 
        catch (System.Xml.XPath.XPathException ePath)
        {
            //System.Windows.Forms.MessageBox.Show(ePath.Message + " : " + ePath.InnerException.ToString());
 
        }
        catch (Exception e)
        {
            //System.Windows.Forms.MessageBox.Show(e.Message + " : " + e.InnerException.ToString());
 
        }
    }
 
}
Code XML : 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
<Alerte>    
  <Donnees>      
    <IdentifiantUnique>PRO_e96d6ffa-ca9e-4226-b937                                </IdentifiantUnique>      
		<CodeProcessus>EDITION</CodeProcessus>		
		<DateEmission>2013-09-11T23:35:36</DateEmission>
		<ArrayOfDonneeFormulaire>
			<DonneeFormulaire>          
				<ListDonneesFormulaireAfficher>true</ListDonneesFormulaireAfficher>          
				<ListDonneesFormulaireCodeQuestion>contact_companyname</ListDonneesFormulaireCodeQuestion>          
				<ListDonneesFormulaireLibelleQuestion>Nom de l'entreprise : </ListDonneesFormulaireLibelleQuestion>          
				<ListDonneesFormulaireValeurReponse>PRO BTP</ListDonneesFormulaireValeurReponse>        
			</DonneeFormulaire>
			<DonneeFormulaire>          
				<ListDonneesFormulaireAfficher>true</ListDonneesFormulaireAfficher>          
				<ListDonneesFormulaireCodeQuestion>contact_siret</ListDonneesFormulaireCodeQuestion>          
				<ListDonneesFormulaireLibelleQuestion>N° siret : </ListDonneesFormulaireLibelleQuestion>          
				<ListDonneesFormulaireValeurReponse>12345627800018</ListDonneesFormulaireValeurReponse>        
			</DonneeFormulaire>
			<DonneeFormulaire>          
				<ListDonneesFormulaireAfficher>true</ListDonneesFormulaireAfficher>          
				<ListDonneesFormulaireCodeQuestion>contact_activity</ListDonneesFormulaireCodeQuestion>          
				<ListDonneesFormulaireLibelleQuestion>Activité : </ListDonneesFormulaireLibelleQuestion>          
				<ListDonneesFormulaireValeurReponse>travaux d'installation d'eau</ListDonneesFormulaireValeurReponse>        
			</DonneeFormulaire>
		</ArrayOfDonneeFormulaire>
	</Donnees>  
</Alerte>