es.instanceGetAttachments( entity-document as Node ) as Sequence
This function is deprecated and will be removed in a future release.
Extract attachments from an entity service document.
Parameters | |
---|---|
entity-document | An envelope document that contains canonical entity instance(s). Data must be stored within the envelope's attachments node. |
Out of the box, Entity Services modules store the original source data
for an entity unchanged within the es:attachments
element
of the envelope document. This function returns just these source
attachments from the envelope.
If the original source is XML, then the attachments contain the source root node as a child element by default. If the original source is JSON, then the attachment contains the source serialized to text; you can use functions such as to convert the text to a JSON object.
/* Assume /es-gs/env/1234.xml is an envelope document with * the following contents: <es:envelope xmlns:es="http://marklogic.com/entity-services"> <es:instance> <es:info> <es:title>Person</es:title> <es:version>0.0.1</es:version> </es:info> <Person> <id>1234</id> <firstName>George</firstName> <lastName>Washington</lastName> <fullName>George Washington</fullName> </Person> </es:instance> <es:attachments> <person> <pid>1234</pid> <given>George</given> <family>Washington</family> </person> </es:attachments> </es:envelope> */ const es = require('/MarkLogic/entity-services/entity-services'); fn.head( es.instanceGetAttachments(cts.doc('/es-gs/env/1234.xml')) ); /* Returns the following XML node <person xmlns:es="http://marklogic.com/entity-services"> <id>1234</id> <given>George</given> <family>Washington</family> </person> */
/* Assume /es-gs/env/1234.xml is an envelope document with * the following contents. Note the attachment is serialized JSON. <es:envelope xmlns:es="http://marklogic.com/entity-services"> <es:instance> <es:info> <es:title>Person</es:title> <es:version>0.0.1</es:version> </es:info> <Person> <id>2345</id> <firstName>Martha</firstName> <lastName>Washington</lastName> <fullName>Martha Washington</fullName> </Person> </es:instance> <es:attachments>{"pid":2345, "given":"Martha", "family":"Washington"}</es:attachments> </es:envelope> */ const es = require('/MarkLogic/entity-services/entity-services'); xdmp.unquote(fn.head( es.instanceGetAttachments(cts.doc('/es-gs/env/2345.xml')) )); // Returns the following JSON object. If you do not call xdmp.unquote, // the result is a string containing the serialized JSON. // // {"pid":2345, "given":"Martha", "family":"Washington"}