I'm trying to execute this query:
declare variable $doc as xs:string external;
declare namespace type4="http:///de/tudarmstadt/ukp/dkpro/core/api/segmentation/type.ecore";
fn:doc($doc)//type4:Lemma/@value
within the BaseX java driver. The actual code snippet looks like this:
String queryString = "declare variable $doc as xs:string external; " +
"declare namespace type4=\"http:///de/tudarmstadt/ukp/dkpro/core/api/segmentation/type.ecore\"; " +
"fn:doc($doc)//type4:Lemma/@value";
Set<String> lemmata = new TreeSet<>();
try (ClientQuery query = this.clientSession.query(queryString))
{
query.bind("$doc", this.getUriFromDocumentId(documentId));
while (query.more())
{
String next = query.next();
logger.info(next);
lemmata.add(next);
}
return lemmata;
} catch (IOException e)
{
e.printStackTrace();
throw new QHException(e);
}
And I'm getting this exception:
[XPST0003] Unexpected end of query: 'namespace type4...'
when calling query.more()
.
Am I declaring the namespace wrong? Is there a mistake in the escaped quotes in the java code? I don't understand where xquery gets the end of query from.
The namespace is also declared in the xml documents which I am querying.
EDIT: this.getUriFromDocumentId(String documentId) just prepends the database name so that the uri is complete and actually matches the document I want to query. I check, that said document exists, before the code snippet above is executed.