Parsing d'un fichier xml ayant 2 racines.
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:
Code:
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> |
Et j'ai proposé un code mais :( ça n'a pas fonctionné:
Code:
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();
}
} |
Mon but est de retourner les données dans la balise transition et voyons que cette balise est sous 2 racines(pnml et net).
Alors comment sera mon code pour afficher la valeur des transitions?
Aidez moi svp et Merci