es:model-from-xml( $model as node() ) as map:map
This function is deprecated and will be removed in a future release.
Create a basic model from an XML model descriptor, without validating
the input descriptor for correctness.
Parameters | |
---|---|
model |
A valid XML model descriptor, as an es:model element or
as a document with an es:model element as its root.
|
Use es:model-validate to validate the descriptor while creating a basic model
There is no equivalent to this function for JSON because the JSON representation of a valid model descriptor is identical to the corresponding basic model.
(: Create a basic model from an XML model descriptor :) xquery version "1.0-ml"; import module namespace es = "http://marklogic.com/entity-services" at "/MarkLogic/entity-services/entity-services.xqy"; es:model-from-xml( <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 basic model, as a <json:object/>. You can inspect the contents using map:map functions, as well as passing the basic model to any Entity Services functions that expect a basic model as input. The JSON serialization is equivalent to the following: { "info": { "title": "Example", "version": "1.0.0" }, "definitions": { "Name": { "properties": { "first": { "datatype": "string" }, "middle": { "datatype": "string" }, "last": { "datatype": "string" } }, "required": [ "first", "last" ] } } } :)
(: Create a basic model from an XML model descriptor stored in the database, : and use it as a map:map. Refer to the previous example for the descriptor : contents. :) xquery version "1.0-ml"; import module namespace es = "http://marklogic.com/entity-services" at "/MarkLogic/entity-services/entity-services.xqy"; let $model-desc := fn:doc("/descriptors/name.xml") let $basic-model := es:model-from-xml($model-desc) return map:get($basic-model, "info") (: ==> The value of the "info" property of the basic model. The value is a <json:object/>. The JSON serialization appears as follows: {"title":"Example", "version":"1.0.0"} :)