Bonjour à tous,
Je suis en train de reprendre un projet dans lequel je manipule un fichier XML que je dois requêter et mes souvenirs en la matière commençant à être lointains, je n'arrive pas à mes fins.
Le fichier XML est structuré comme suit :
Je cherche à récupérer une liste sans doublons des "département" de la région "BRETAGNE".
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 <communes> <commune> <region>BRETAGNE</region> <departement>35</departement> <designation_departement>ILLE ET VILAINE</designation_departement> <codepostal>35000</codepostal> <designation>RENNES</designation> </commune> <commune> <region>BRETAGNE</region> <departement>35</departement> <designation_departement>ILLE ET VILAINE</designation_departement> <codepostal>35300</codepostal> <designation>FOUGERES</designation> </commune> <commune> <region>BRETAGNE</region> <departement>56</departement> <designation_departement>MORBIHAN</designation_departement> <codepostal>56000</codepostal> <designation>VANNES</designation> </commune> <commune> <region>NORMANDIE</region> <departement>14</departement> <designation_departement>CALVADOS</designation_departement> <codepostal>14000</codepostal> <designation>CAEN</designation> </commune> </communes>
J'ai essayé quelques requêtes du type :
mais la liste retournée est vide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 var départements = (from département in xelement.Elements("commune").Elements("département") where département.Elements("region").ToString().Equals("BRETAGNE") select département).GroupBy(x => x.Value).Select(x => x.First());
Où est-ce que je me trompe ?
D'avance merci pour votre aide.
Partager