Loading TOC...

MarkLogic 12 EA 2 Product Documentation
op:validate-doc

op:validate-doc(
   $validateDocCol as item(),
   $schemaDef as map:map
) as map:map

Summary

Validate the document based on a supplied schema. This schema needs to be stored in the schema database. Check appserver error log for validate errors.

Parameters
$validateDocCol This is the column which contains the document to validate. This can be a string of the column name or an op:col. Use op:view-col or op:schema-col if you need to identify columns in the two views that have the same column name.
$schemaDef The required 'kind' key of the schemaDef map must be 'jsonSchema', 'schematron', or 'xmlSchema'. When 'kind' is 'jsonSchema' or 'schemtron' then a key 'schemaUri' is required. Key 'mode' takes 'strict', 'lax' or 'type' (refer to xdmp:validate).

See Also

Example

xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

let $doc-descriptors := (
    map:entry("uri", '/optic/validateDoc/toValidate1.xml'),
    map:entry("uri", '/optic/validateDoc/toValidate2.xml'),
    map:entry("uri", '/optic/validateDoc/toValidate3.xml')
  )
let $schemadef := map:entry("kind", "xmlSchema")=>map:with("mode", "strict")
return op:from-doc-descriptors($doc-descriptors, "view")
=>op:join-doc-cols(op:doc-cols("view"), op:view-col("view", "uri"))
=>op:validate-doc(op:view-col("view", "doc"), $schemadef)
=>op:result()
  

Example

xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

let $doc-descriptors := (
    map:entry("uri", '/optic/validateDoc/toValidate1.xml'),
    map:entry("uri", '/optic/validateDoc/toValidate2.xml'),
    map:entry("uri", '/optic/validateDoc/toValidate3.xml'),
    map:entry("uri", '/optic/validateDoc/toValidate4.xml')
  )
let $schemadef := map:entry("kind", "xmlSchema")=>map:with("mode", "type")=>map:with("type", fn:QName("http://marklogic.com/xdmp/group", "count"))
return op:from-doc-descriptors($doc-descriptors)
=>op:join-doc-cols((), op:col("uri"))
=>op:order-by("uri")
=>op:validate-doc("doc", $schemadef)
=>op:result()
  

Example

xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

let $doc-descriptors := (
    map:entry("uri", '/optic/validateDoc/validate1.json'),
    map:entry("uri", '/optic/validateDoc/validate2.json'),
    map:entry("uri", '/optic/validateDoc/validate3.json'),
    map:entry("uri", '/optic/validateDoc/validate4.json')
  )
let $schemadef := map:entry("kind", "jsonSchema")
    =>map:with("schemaUri", "/validateDoc-test.json")
    =>map:with("mode", "full")
return op:from-doc-descriptors($doc-descriptors)
=>op:join-doc-cols((), op:col("uri"))
=>op:order-by("uri")
=>op:validate-doc("doc", $schemadef)
=>op:result()
  

Example

xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

let $doc-descriptors := (
    map:entry("uri", '/optic/validateDoc/toValidateSchematron1.xml'),
    map:entry("uri", '/optic/validateDoc/toValidateSchematron2.xml'),
    map:entry("uri", '/optic/validateDoc/toValidateSchematron3.xml')
  )
let $schemadef := map:entry("kind", "schematron")
    =>map:with("schemaUri", "/validateDoc-test.sch")
return op:from-doc-descriptors($doc-descriptors, "view")
=>op:join-doc-cols(op:doc-cols("view"), op:view-col("view","uri"))
=>op:validate-doc(op:view-col("view","doc"), $schemadef)
=>op:result()
  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.