Avinash Shukla
Avinash Shukla

Reputation: 201

Automatic schema validation in MarkLogic

Is there a way to automatically validate an XML document against a schema stored in the schema database? By automatic, I mean that if try to insert an invalid XML document (as per schema) using the xdmp:document-insert() function, it should not allow it and throw a relevant error.

I tried it, but even if the XML document doesn't match the schema, it is inserted without any errors. If I validate the same XML using the xdmp:validate() function, it shows errors as expected.

Note: I have added targetNamespace attribute to the schema document, and used the same namespace in the XML document.

Upvotes: 1

Views: 72

Answers (1)

You Cannot force MarkLogic to validate during xdmp:document-insert() via an option on the function.

I see two choices for You:

  1. Make Your own function that first validates and then calls document-insert
  2. Validate as part of a pre-commit trigger. If you make this code in a way that throws an error on validation failure, then the transaction is rolled back (for all docs in the transaction). This is because the pre-commit trigger runs in the same transaction and context as the document being inserted. See here: Pre-Commit Trigger

Upvotes: 1

Related Questions