es.schemaGenerate( model as Object ) as Sequence
This function is deprecated and will be removed in a future release.
Generate an XSD schema that can be used to validate instance data.
Parameters | |
---|---|
model | A valid basic entity model. |
If the source model includes multiple entity type definitions and the entity types define different entity instance namespace URIs, then this function generates a schema for each namespace.
// Generate a schema from a basic model and then save it to a file. const es = require('/MarkLogic/entity-services/entity-services'); const basicModel = fn.doc("/es-ex/models/name.json"); const schema = fn.head(es.schemaGenerate(basicModel)); xdmp.save("/somewhere/name.xsd", schema); // Customize the schema as needed, then deploy it to the schemas database. // Once deployed, you can use the schema to validate instance data, // similar to the following example: const instanceData = cts.doc('/instances/name/some-instance.xml'); xdmp.validate(instanceData, 'strict');
// Generate a schema from a model. const es = require('/MarkLogic/entity-services/entity-services'); fn.head( es.schemaGenerate( { "info": { "title": "Example", "version": "1.0.0" }, "definitions": { "Name": { "properties": { "first": { "datatype": "string" }, "middle": { "datatype": "string" }, "last": { "datatype": "string" } }, "required": [ "first", "last" ] } } } )); /* Result: A schema similar to the following. <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sem="http://marklogic.com/semantics" xmlns:es="http://marklogic.com/entity-services"> <xs:element name="first" type="xs:string"/> <xs:element name="middle" type="xs:string"/> <xs:element name="last" type="xs:string"/> <xs:complexType name="NameType" mixed="true"> <xs:sequence minOccurs="0"> <xs:element ref="first"/> <xs:element minOccurs="0" ref="middle"/> <xs:element ref="last"/> </xs:sequence> </xs:complexType> <xs:element name="Name" type="NameType"/> </xs:schema> */
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.