Reputation: 655
I hava a schema in schema database of marklogic. Is there a way to do strict validation when I insert a document using Java API against the schema in database and throw an error if its not valid.
Any help on how to approach the solution through is greatly appreciated.
Upvotes: 2
Views: 482
Reputation: 2475
The answer for the Java API is the same as it is for the REST API. You can install a REST transform. It can be this simple:
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.
You could also implement this transform using Javascript. For more see Writing Transformations in the REST Application Developer's Guide.
Upvotes: 2