process Xquery with saxon9



I'm new with saxon9- and i want to processing a Xquery against a XML, i use this XML



<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia Records</company>
<price>10.90</price><year>1985</year>
</cd>
<cd>
<title>Hide Your Heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price><year>1988</year>
</cd>
<cd>
<title>Best of Enya</title>
<artist>Enya</artist>
<country>UK</country>
<company>ABC Records</company>
<price>9.90</price>
<year>1995</year>
</cd>
</catalog>


I want to execute any Xquery against this xml, i have seen in saxon9api but i don't understand somethings, i find this code in saxon9 but i dont understand it



public void runXquery(String file, String expresion) throws SaxonApiException{
Processor proc = new Processor(false);
XQueryCompiler comp = proc.newXQueryCompiler();
comp.declareNamespace("xsd", "http://ift.tt/tphNwY");
XQueryExecutable exp = comp.compile("<catalog>{//ITEM[1]}</catalog>");
XQueryEvaluator qe = exp.load();

File inputFile = new File("xmlToHtml/catalog.xml");
FileInputStream fis;
try {
fis = new FileInputStream(inputFile);
} catch (FileNotFoundException e) {
throw new SaxonApiException(
"Input file not found. The current directory should be the Saxon samples directory");
}
SAXSource source = new SAXSource(new InputSource(fis));
source.setSystemId(inputFile.toURI().toString());

qe.setSource(source);

ContentHandler ch = new XMLFilterImpl() {

public void startElement(String uri, String localName, String qName) throws SAXException {
System.out.println("start element {" + uri + "}" + localName);
}

public void endElement(String uri, String localName, String qName) throws SAXException {
System.out.println("End element {" + uri + "}" + localName);
}

};
qe.run(new SAXDestination(ch));


}

No comments:

Post a Comment