Haskell 从HXT中失败的Relax NG验证读取状态

Haskell 从HXT中失败的Relax NG验证读取状态,haskell,relaxng,hxt,Haskell,Relaxng,Hxt,在Haskell中验证XML文件在HXT和RELAXNG中运行良好,除了一件事:如何获得结果 使用以下代码,XML文件xmlFilename将根据Relax NG方案rngFilename进行验证。如果出现错误,则将错误输出到stderr,并继续评估 v <- runX ( readDocument [ withRemoveWS yes -- remove redundant whitespace , withValidate no --

在Haskell中验证XML文件在HXT和RELAXNG中运行良好,除了一件事:如何获得结果

使用以下代码,XML文件
xmlFilename
将根据Relax NG方案
rngFilename
进行验证。如果出现错误,则将错误输出到
stderr
,并继续评估

v <- runX
    ( readDocument
        [ withRemoveWS yes   -- remove redundant whitespace
        , withValidate no    -- don't validate source by DTD
        ] xmlFilename
      >>>
      -- validate source by Relax NG
      validateDocumentWithRelaxSchema [] rngFilename
    )
现在问题是:

如何检查
ValidatedDocumentWithRelaxSchema的输出
是否存在验证错误?


是否有一个预定义的函数可供我使用(但尚未找到)?好的,我自己找到了答案:

HXT错误处理位于中,具有有趣的函数
getErrStatus

v <- runX
    ( readDocument
        [ withRemoveWS yes   -- remove redundant whitespace
        , withValidate no    -- don't validate source by DTD
        ] xmlFilename
      >>>
      -- validate source by Relax NG
      validateDocumentWithRelaxSchema [] rngFilename
      >>>
      getErrStatus
    )

case v of
    --severity [0]=[c_ok]
    [0] -> --continue processing

    --severity: [1]=[c_warn], [2]=[c_err], [3]=[c_fatal], else=something_really_really_bad_happened
    _ -> --do error handling

v这样,所有错误消息都会输出到
stderr
。使用
errorMsgCollect
和之后的
getErrorMessages
可以避免这种情况,但我不确定如何返回两个箭头(getErrorMessages
getErrStatus
的结果)。
v <- runX
    ( readDocument
        [ withRemoveWS yes   -- remove redundant whitespace
        , withValidate no    -- don't validate source by DTD
        ] xmlFilename
      >>>
      -- validate source by Relax NG
      validateDocumentWithRelaxSchema [] rngFilename
      >>>
      getErrStatus
    )

case v of
    --severity [0]=[c_ok]
    [0] -> --continue processing

    --severity: [1]=[c_warn], [2]=[c_err], [3]=[c_fatal], else=something_really_really_bad_happened
    _ -> --do error handling