简体   繁体   中英

exerr:ERROR err:XPST0003: EOF or zero-length string found where a valid XPath expression was expected

I'm a beginner at XQuery. I'm trying to write a function for a project, but I get this error message:

exerr:ERROR err:XPST0003: EOF or zero-length string found where a valid XPath expression was expected.

This is my XQuery:

xquery version "3.0";

declare function local:trovaMatricola($str as xs:string?){
 let $liv := doc("/db/apps/prova/data/utenti.xml")/utenti/utente[matricola=$str]/livello
 let $val := local:valore($liv)
 return $val
};

declare function local:valore($liv as xs:string?){
 let $val := doc("/db/apps/prova/data/fiaba.xml")/text/$liv
 return $val
};

If you're not writing XQuery modules, you need to supply an actual query. As is, you only declared the XQuery version and two functions, but there is nothing to be actually executed.

This also explains the error message:

exerr:ERROR err:XPST0003: EOF or zero-length string found where a valid XPath expression was expected.

The XQuery engine parsed the functions, but is still looking for a statement to execute. The restriction to "XPath expressions" seems a little bit misleading.

@JensErat has given you the answer, but to add to it, here's a tip: there are quite a few XQuery engines about, and if you are mystified by an error message from one of them, it may be a good idea to see what a different XQuery engine tells you. None of them will ever get all diagnostics perfectly right, but here is what Saxon tells you for this query:

Syntax error on line 12 at column 4 of file:/Users/mike/Desktop/temp/test.xq near {...ml")/text/$liv return $val ...} 
  XPST0003: The main module must contain a query expression after any declarations in the prolog
Syntax error on line 12 at column 4 of file:/Users/mike/Desktop/temp/test.xq near {...ml")/text/$liv return $val ...} 
  XPST0003: Unexpected token "<eof>" in path expression
Static error(s) in query

I can't say I'm entirely happy with that: the second message is redundant, and the reference to a "path expression" rather odd; also some users might not know that <eof> means "end of file" or that lexers often treat end-of-file as a pseudo-token; but the first message is spot-on and would have avoided the need for you to post here for an explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM