es.modelToXml

es.modelToXml(
   model as Object
) as element(es.model)

Summary

This function is deprecated and will not be supported in MarkLogic 11.
Serialize a basic model as an XML element.

Parameters
model A valid basic model.

Example

// 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>
 */
  

Example

// 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>
*/
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy