
es:schema-generate( $model as map:map ) as element(xsd:schema)*
This function is deprecated and will not be supported in MarkLogic 11.
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 model and save it to a file. :)
xquery version "1.0-ml";
import module namespace es = "http://marklogic.com/entity-services"
at "/MarkLogic/entity-services/entity-services.xqy";
let $basic-model := fn:doc("/es-ex/models/name.json")
let $schema := es:schema-generate($basic-model)[1]
return xdmp:save("/somewhere/name.xsd", $schema);
(: Customize schemas as needed, then deploy it to the schemas database.
: You can use the deployed schema as follows:
:)
let $instance-data := fn:doc("/instances/names/some-instance.xml")
return xdmp:validate($instance-data, "strict")
(: Generate a schema from a model :)
xquery version "1.0-ml";
import module namespace es = "http://marklogic.com/entity-services"
at "/MarkLogic/entity-services/entity-services.xqy";
es:schema-generate( es:model-validate(
<es:model xmlns:es="http://marklogic.com/entity-services">
<es:info>
<es:title>Example</es:title>
<es:version>1.0.0</es:version>
</es:info>
<es:definitions>
<Name>
<es:properties>
<first><es:datatype>string</es:datatype></first>
<middle><es:datatype>string</es:datatype></middle>
<last><es:datatype>string</es:datatype></last>
</es:properties>
<es:required>first</es:required>
<es:required>last</es:required>
</Name>
</es:definitions>
</es:model>
))
(: ==> 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.