Hi,
I have this XML document that i want to query using XQuery :
<!--?xml version="1.0" encoding="UTF-8"?-->
Renault
18
noir
Peugeot
10
rouge
Mercedes
9
gris
BMW
7
bleu
Let's say i want to query the value of the element for the
element COUPE and the element PEUGEOT:
so it should return 10
I want to write a little program that returns it using XMLBeans and
XQuery.Here is what i got so far :
import java.io.File;
import noNamespace.ParcautomobileDocument;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
public class XqueryXML {
public static void main(String[] args) throws Exception
{
XmlObject resultXml =null;
ParcautomobileDocument parcautomobile =
ParcautomobileDocument.Factory.parse(new File ("d:/parcAuto.xml"));
//String expression =
"$this/parcautomobile/vehicule[@modele='berline']/marque/nom";
String expression =
"for $e in //parcautomobile/vehicule " +
"let $s := $e/@modele " +
"where $s = 'Peugeot' " +
"return $e//couleur";
XmlCursor monCursor = parcautomobile.newCursor().execQuery(expression);
if (monCursor.getSelectionCount() > 0)
{
System.out.println("monCursor is not empty");
resultXml = monCursor.getObject();
System.out.println(resultXml.toString());
monCursor.dispose();
}
}
}
It does not return anything.
What XQuery expression exactly should i write in order to return 10, the
number of PEUGEOT vehicules ?
Thanks for your help