попробуйте с этим,
XQueryMain.java (java)
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import javax.xml.xquery.XQConnection;
import javax.xml.xquery.XQDataSource;
import javax.xml.xquery.XQException;
import javax.xml.xquery.XQPreparedExpression;
import javax.xml.xquery.XQResultSequence;
import com.saxonica.xqj.SaxonXQDataSource;
public class XQueryMain {
public static void main(String[] args){
try {
InputStream inputStream = new FileInputStream(new File("condition.xqy"));
XQDataSource dataSource = new SaxonXQDataSource();
XQConnection connection = dataSource.getConnection();
XQPreparedExpression preparedExpression = connection.prepareExpression(inputStream);
XQResultSequence resultSequence = preparedExpression.executeQuery();
while (resultSequence.next()) {
System.out.println(resultSequence.getItemAsString(null));
}
}
catch (FileNotFoundException | XQException e) {
e.printStackTrace();
}
}
}
condition.xqy (XQuery)
for $x in doc("bookstore.xml")/bookstore/book
where $x/price=30
return $x/title
bookstore.xml (XML)
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
следующие файлы JAR (SaxonHE9-9-0-2J) добавить к пути к классу
- saxon9he.jar
- saxon9-test.jar
- saxon9-xqj.jar