Je cherche un moyen de récupérer dans un xml touts les Strings qui correspondent à l'expression xpath entrée en paramètre
J'ai bien compris comment évaluer un xpath, mais ca ne me retourne que la première valeur rencontré.
comment faire une itération sur tout le xml pour récupérer un tableau de String correspondant à toutes les valeurs rencontrées

Voici ma méthode evaluerSAX
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
 class ExempleXPath{
 
	public void  evaluerSAX(File fichier, String expression, QName retour){
		try{
			//creation de la source
			InputSource source = new InputSource(new FileInputStream(fichier));
 
			//creation du XPath 
			XPathFactory fabrique = XPathFactory.newInstance();
			XPath xpath = fabrique.newXPath();
 
			//evaluation de l'expression XPath
			XPathExpression exp = xpath.compile(expression);
			Object resultat = exp.evaluate(source,retour);
 
			System.out.println(resultat);
		}catch(XPathExpressionException xpee){
			xpee.printStackTrace();
		}catch(IOException  ioe){
			ioe.printStackTrace();	
		}
	}
 
}
Voici une application de la méthode avec une expression xpath entrée en paramètre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
try{
           ExempleXPath exp = new ExempleXPath();
	   File xml = new File("testXml/fichier.xml");
	   exp.evaluerSAX(xml, "//membre[@pseudo=toto]", XPathConstants.STRING);
}catch(Exception e){
			      e.printStackTrace();	
		           }