Loading TOC...

MarkLogic 10 Product Documentation
es:model-from-xml

es:model-from-xml(
   $model as node()
) as map:map

Summary

This function is deprecated and will not be supported in MarkLogic 11.
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.

Usage Notes

This function converts the XML representation of a model descriptor into the in-memory representation of a basic model. This function does not validate the XML, so it is best suited for faster conversion of a descriptor known to be valid. If you supply an invalid model descriptor, the resulting basic model will also be invalid and may result in problems when you try to use other Entity Services APIs on the model.

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.

See Also

Example

(: 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" ]
    }
  }
}

:)
  

Example

(: 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"}

:)
  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.