title: How to find if a document exists in the database using xquery
body: <p>I am using xquery over BaseX XML Database. Say, I have the following documents stored in my database: doc1, doc2, doc3.</p>
  
  <p>What Xquery do I use to check the existence of a given document. I tried the following:</p>
  
  <p>declare variable $doc_name as xs:string external;</p>
  
  <p>return boolean($doc_name)</p>
  
  <p>I expected it to work as follows:
  if doc_name = doc1 return true
  if doc_name = nodoc return false</p>
  
  <p>But, I see an exception:</p>
  
  <p>java.io.IOException: Stopped at line 3, column 7: 
  [XPST0003] Unexpected end of query: 'boolean("doc1")'.</p>
  
  <p>I also tried return</p>
  
  <ul>
  <li><p>return fn:exists($doc_name) and </p></li>
  <li><p>return fn:doc-available(doc_uri)</p></li>
  </ul>
  
  <p>These do not work either. I see the same end of query exception. What is the correct way of checking a document's existence?</p>
  
  <p>Thanks,
  Sony</p>