Loading TOC...

MarkLogic Server 11.0 Product Documentation
es:instance-get-attachments

es:instance-get-attachments(
   $entity-document as document-node()
) as element()*

Summary

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.

Usage Notes

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 xdmp:from-json-string or xdmp:unquote xdmp.fromJsonString or xdmp.unquote to convert the text to a JSON object.

See Also

Example

(: 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>
:)

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

es:instance-get-attachments(fn:doc('/es-gs/env/1234.xml'))

(: Returns a the following XML node
  <person xmlns:es="http://marklogic.com/entity-services">
    <pid>1234</pid>
    <given>George</given>
    <family>Washington</family>
  </person>
:)
  

Example

(: Assume /es-gs/env/2345.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>
:)

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

xdmp:unquote(
  es:instance-get-attachments(fn: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"}
:)
  

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