bonjour,
je souhaite parser un fichier xml,
voici mon codeet voici 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 import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.jdom2.JDOMException; import org.jdom2.input.SAXBuilder; import org.jdom2.Document; import org.jdom2.Element; public class ChargerNotesEtudiants { ArrayList<ArrayList<String>> liste = new ArrayList<ArrayList<String>>(); public ChargerNotesEtudiants (String nomfichier) { SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(nomfichier); try { Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); List list = rootNode.getChildren(); ArrayList<String> l= new ArrayList<>(); for (int i = 0; i < list.size(); i++) { Element node = (Element) list.get(i); System.out.println("nom: " + node.getChildText("nom")); System.out.println("prenom : " + node.getChildText("prenom")); System.out.println("emd2 : " + node.getChildText("emd2")); System.out.println("moyenne : " + node.getChildText("moyenne")); l.add(node.getChildText("nom")); l.add(node.getChildText("prenom")); l.add(node.getChildText("emd2")); l.add(node.getChildText("moyenne")); liste.add(l); } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } } public ArrayList<ArrayList<String>> getListe() { return liste; } public void setListe(ArrayList<ArrayList<String>> liste) { this.liste = liste; } }
et je veux récupérer la liste de liste et voici mon retour :
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 <?xml version="1.0" encoding="UTF-8"?> <html> <etudiant1> <nom>bibi</nom> <prenom>bobo</prenom> <notes> <emd1>12</emd1> <emd2>13</emd2> <moyenne>12.5</moyenne> </notes> </etudiant1> <etudiant2> <nom>titi</nom> <prenom>toto</prenom> <notes> <emd1>10</emd1> <emd2>11</emd2> <moyenne>10.5</moyenne> </notes> </etudiant2> </html>
et je eux que ça me retourne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 list[[bibi, bobo, null, null, titi, toto, null, null], [bibi, bobo, null, null, titi, toto, null, null]]
merci pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 list[[bibi, bobo, null, null], [ titi, toto, null, null]]
Partager