问题
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