Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return Statement in Xquery

Tags:

xml

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 message 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.

like image 327
Kevin Avatar asked Feb 01 '26 20:02

Kevin


1 Answers

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 :)
  }
like image 83
Ghislain Fourny Avatar answered Feb 04 '26 09:02

Ghislain Fourny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!