validate document against xsd using rest api : marklogic

狂风中的少年 提交于 2019-12-25 03:08:46

问题


I am using PUT method of document rest api for inserting document but I want to validate xml document before ingestion using schema if it fails I have to report it back. How can I achieve this within Marklogic using rest api similiar to xdmp:validate() in xquery ?

I have come across approach like pre-commit triggers, creating rest transformation etc..looking for your inputs.


回答1:


Pre-commit triggers are more difficult to configure, and take more overhead. I'd go for a rest transform. That could be as simple as:

xquery version "1.0-ml";

module namespace trans = "http://marklogic.com/rest-api/transform/validate";

declare function trans:transform(
  $context as map:map,
  $params as map:map,
  $content as document-node()
) as document-node()
{
  let $validate := validate strict { $content }
  return $content
};

Note: upload this with transform name 'validate', as transform name must match its namespace.

HTH!



来源:https://stackoverflow.com/questions/30357781/validate-document-against-xsd-using-rest-api-marklogic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!