2016-12-02 42 views
0

我有以下情形:XQuery的错误处理

XQUERY:

declare namespace xs = "http://www.w3.org/2001/XMLSchema"; 


declare variable $udgHeader external; 


let $msg-name := upper-case($udgHeader/msg-name/text()) 
let $recipient := upper-case($udgHeader/recipient/text()) 

return 
<recipients> 
    <recipient> 
     <dest> 
     { 
      if (($msg-name = "ARS_ISTP") and ($recipient = "ISTP")) then 

       'IstpArs' 

      else if (($msg-name = "ARS_ESM") and ($recipient = "ESM")) then 

       'EsmArs' 

      else 


       error(xs:QName('fase'), concat("Unknown msg-name/recipient combination ['", $msg-name,"'/'", $recipient, "']! Please check fase recipient list.")) 

     } 
     </dest> 
    </recipient> 
</recipients> 

我进来的XML将抛出错误。

此错误我想用Java(负测试)与文件(预期结果)进行比较。

预期结果内容:

Unknown msg-name/recipient combination ['ARS_XYZ'/'ARS']! Please check fase recipient list. 

我的问题是,我得到这个错误:

org.apache.xmlbeans.XmlRuntimeException: weblogic.xml.query.exceptions.XQueryUserException: line 29, column 5: fase: Unknown msg-name/recipient combination ['ARS_XYZ'/'ESM']! Please check fase recipient list. 

我该如何处理此错误,以配合我预期的结果?

回答

1

当您调用error()会发生什么的细节有点依赖于您的处理器API,但在Java环境中,我期望您的查询处理器的调用以异常而不是正常结果退出。如果你想得到一个正常的结果,那么返回一些你认为是错误结果的元素(或其他对象),而不是调用error()。

在3.0/3.1中,您可以通过在发生错误时调用error()来实现此目的,然后使用查询顶级的try/catch来捕获它。