es.modelToXml( model as Object ) as element(es.model)
This function is deprecated and will be removed in a future release.
Serialize a basic model as an XML element.
Parameters | |
---|---|
model | A valid basic model. |
// Serialize an in-memory model descriptor to XML. const es = require('/MarkLogic/entity-services/entity-services'); const model = es.modelValidate( { "info": { "title": "Example", "description": "ES Examples", "version": "1.0.0", }, "definitions": { "Name" : { "properties": { "first": { "datatype": "string" }, "middle": { "datatype": "string" }, "last": { "datatype": "string" } }, "required": ["first", "last"] } }} ); es.modelToXml(model); /* The model descriptor, serialized as XML. You should get output similar * to the following: <es:model xmlns:es="http://marklogic.com/entity-services"> <es:info> <es:title>Example</es:title> <es:version>1.0.0</es:version> <es:description>ES Examples</es:description> </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> */
// Serialize a model stored in the database. const es = require('/MarkLogic/entity-services/entity-services'); const modelDesc = fn.doc('/models/name.json'); es.modelToXml(modelDesc); /* Result: The model descriptor, serialized as XML. For example, assuming * /models/name.json contains the model from the previous example, you should * see output similar to the following: <es:model xmlns:es="http://marklogic.com/entity-services"> <es:info> <es:title>Example</es:title> <es:version>1.0.0</es:version> <es:description>ES Examples</es:description> </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> */
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.