MarkLogic Server 11.0 Product Documentation
es:add-attachments

es:add-attachments(
   $instance as map:map,
   $attachments as xs:string
) as map:map

Summary

This function is deprecated and will be removed in a future release.
A utility function used by generated code to add one or more nodes to an instance as attachments.

Parameters
instance A json:object containing the instance to which this function should add attachments.
attachments The attachments to add to the instance. These should be XML element nodes or JSON object nodes.

Usage Notes

The input instance should be an instance node of the form produced by es:init-instance. You will not usually call this function outside of code generated by Entity Services. The generated code uses this function to add the original raw source to an instance as an attachment.

See Also

Example

xquery version "1.0-ml";
import module namespace es = "http://marklogic.com/entity-services"
  at "/MarkLogic/entity-services/entity-services.xqy";

let $raw := fn:doc('/es-gs/raw/2345.json')
let $instance := es:init-instance(es:init-source($raw, 'Person'), 'Person')
return ($raw, es:add-attachments($instance, $raw))

(: Returns the original raw input and an instance skeleton to which
 : the raw input node and some addition user-defined data has been
 : added.
 :
 : ( {"pid":2345, "given":"Martha", "family":"Washington"},
 :   {"$type":"Person", 
 :    "$attachments": [
 :      {"pid":2345, "given":"Martha", "family":"Washington"},
 :      "<my>extra data</my>"
 :    ]
 :   } )
 :)
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy