Bonjour,

J'utilise JDOM et org.jdom.xpath.XPath dans mon projet.

Je viens de m'apercevoir que l'interface org.jdom.xpath.XPath ne retourne que des nodeset et ne permet pas de retourner des String calculées par la fonction XSL number(nodeset) par exemple.

Par contre l'interface javax.xml.xpath.XPath qui utilise DOM, le permet via la méthode javax.xml.xpath.xPathExpression.evaluate.
J'ai la solution de convertir mon JDOM en DOM pour cette unique occasion mais est ce que j'ai d'autres possibilités ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
<A>
	<B>...</B>	
	<B>...</B>	
	<B>...</B>	
	<B>...</B>	
	<section> ...</section>			
</A>
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
 
private String calculeNombreB(Element section) {
 
	String nombreDeBaliseB = "";
 
	javax.xml.xpath.XPathFactory xPathFactory = null;
	javax.xml.xpath.XPath xpath = null;
 
 
	xPathFactory  = XPathFactory.newInstance();
	xpath = xPathFactory.newXPath();
	String expression = "number(preceding-sibling::B)";
 
	javax.xml.xpath.XPathExpression xPathExpression;
 
	try {
		xPathExpression = xpath.compile(expression);
                //L'element section doit être une element Dom et non Jdom comme dans mon cas
		nombreDeBaliseP = (String) xPathExpression.evaluate(section, XPathConstants.STRING);
	} catch (XPathExpressionException e1) {
		e1.printStackTrace();
	}
	return 	nombreDeBaliseB;
}
Résultat attendu >> nombreDeBalise B="4"