Voici mon fichier xml :
Voici mon code Xpath en 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 <root> <aaa> <bbb> <ccc> <e nom="fr"></e> <e nom="en"></e> </ccc> </bbb> <bbb> <ccc> <e nom="fr"></e> <e nom="en"></e> </ccc> </bbb> </aaa> </root>
Ma liste d'element "bbb" est complete mais mon Element elem est null, je ne comprends pas pourquoi.
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 XPath xpa = XPath.newInstance("//bbb"); List<?> lbbb = xpa.selectNodes(root); Iterator<?> iter = lbbb.iterator() ; Element noeudCourant = null; while (iter.hasNext()) { noeudCourant = (Element) iter.next(); XPath xpa2 = XPath.newInstance("./ccc/e[@nom='fr']"); Element elem = (Element) xpa2.selectSingleNode(noeudCourant); }
Merci
Partager