Return Statement in Xquery
I want to change my current return statement in my XQuery, which is :
return
<p>XML File Stored Successfully</p>
I want to make this return statement capable of handling the situation if there is an error, then return an error code to the user, if there is no error, then return the messag开发者_C百科e above to the user.
I think an if-else construct should be placed under return for my purpose. But I really have no idea what condition should be there for the if, could experts help a little? Thanks in advance.
The XQuery 3.0 working draft introduces try-catch expressions, which might be what you are looking for:
declare namespace err = "http://www.w3.org/2005/xqt-errors";
let $x := "string"
return
try {
$x cast as xs:integer
} catch * {
$err:code (: this variable contains the error code :)
}
精彩评论