Bonjour,
J'ai utilisé ce Tutorial pour parser un fichier xml : http://cynober.developpez.com/tutoriel/java/xml/jdom/
Mais le problème est que mon fichier xml n'a pas la même forme que celle dans le tutoriel. Mon fichier est sous la forme:
Et j'ai proposé un code mais
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <?xml version="1.0" encoding="UTF-8"?> <pnml> <net> <transition> ................... </transition> <transition> ................... </transition> </net> </pnml>ça n'a pas fonctionné:
Mon but est de retourner les données dans la balise transition et voyons que cette balise est sous 2 racines(pnml et net).
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 public class Transformer { static org.jdom.Document document; static Element racine; static void afficheALL() { List list1 = racine.getChildren("pnml"); Iterator i = list1.iterator(); while(i.hasNext()) { List list2 = racine.getChildren("net"); Iterator i1 = list2.iterator(); while (i1.hasNext()) { Element courant = (Element)i.next(); System.out.println(courant.getChild("transition").getText()); } } } public static void main(String[] args) { SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(new File("D:/buffer.xml")); } catch(Exception e){} racine = document.getRootElement(); afficheALL(); } }
Alors comment sera mon code pour afficher la valeur des transitions?
Aidez moi svp et Merci
Partager