Sundeep Kumar Mehta
Sundeep Kumar Mehta

Reputation: 89

validate document against xsd using rest api : marklogic

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.

Upvotes: 0

Views: 327

Answers (1)

grtjn
grtjn

Reputation: 20414

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!

Upvotes: 3

Related Questions