Récuperer la valeur d'un child
Bonsoir,
J ' ai un fichier Xml constitué comme ceci:
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
| <?xml version="1.0" encoding="UTF-8"?>
<requetes>
<header>
<champ1>
<lg>6</lg>
</champ1>
<champ2>
<lg>4</lg>
</champ2>
<champ3>
<lg>6</lg>
</champ3>
</header>
<body>
<Champ1>
<lg>6</lg>
</Champ1>
<Champ2>
<lg>20</lg>
</Champ2>
<Champ3>
<lg>20</lg>
</Champ3>
</body>
</requetes> |
Ce que je voudrais faire , c ' est de récupérer toute les valeurs de la balise <lg> appartenant au parent <body>
Or , je n ' arrive qu ' a accéder a Champ1,champ2,champ3, et je voudrais savoir comment descendre d ' un noeud encore en dessous .
Voici ma fonction:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public Object[] afficherTailleParametres()
{
initialiserXml("ressources/fichiersXML/requetes/DEPMSG2.xml");
List listeParametres = racine.getChildren("body");
System.out.println(racine.getChildren("body));
Iterator i = listeParametres.iterator();
while(i.hasNext())
{
Element courant = (Element)i.next();
for (int j=0;j<courant.getChildren().size();j++)
{
System.out.println(courant.getChildTextTrim("lg"));
// retourne toujours null
}
}
return null;
} |
Merci de votre aide