Bonjour voila je cherche a lire plusieurs balise dans un même nœuds.
Xml :
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <?xml version="1.0" encoding="UTF-8"?> <personnes> <etudiant> <nom>Test0</nom> <nom>Test1</nom> </etudiant> <etudiant> <nom>Test2</nom> </etudiant> </personnes>
Java :
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 static org.jdom.Document document; static Element racine; public static void main(String[] args) { SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(new File("Exercice2.xml")); } catch (Exception ex) { System.err.println("Document pas trouvé"); } racine = document.getRootElement(); affiche(); } static void affiche() { List listEtudiants = racine.getChildren("etudiant"); Iterator i = listEtudiants.iterator(); while (i.hasNext()) { Element courant = (Element) i.next(); System.out.println(courant.getChild("nom").getText()); } }
Voila donc je voudrais afficher Test0, Test1, Test2 mais je ne peux afficher que Test0 et Test2.
Merci
Partager