<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.multipartEncode.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.multipartEncode</api:function-name><api:suggest>xdmp.multipartencode</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>multipartencode</api:suggest><api:function-link mode="xquery" fullname="xdmp:multipart-encode">/apidoc/8.0/xdmp:multipart-encode.xml</api:function-link><api:function mode="javascript" name="multipartEncode" type="builtin" lib="xdmp" category="Extension" subcategory="Extension" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.multipartEncode"><api:summary>
  <p xmlns="http://www.w3.org/1999/xhtml">Create a multipart encoding of the specified node. The returned binary
  node can be passed to <a href="./xdmp:http-post">xdmp:http-post</a>.
  The manifest is modeled after the
  manifest that is passed to <a href="./xdmp:zip-create">zip:create</a>,
  with the headers element being
  the same as is described for <a href="./xdmp:http-get">xdmp:http-get</a>
  allowing users to add arbitrary
  headers to each part. If a content-type header is not specified for a part,
  it will be determined if possible from the content.</p>

  <p xmlns="http://www.w3.org/1999/xhtml">There should be one part element for each node in the content sequence.</p>

  <p xmlns="http://www.w3.org/1999/xhtml">Each part also has an optional options node to control how xml or text
  will be serialized. The two options are the same as for
  <a href="./xdmp:save">xdmp:save</a>.</p>

  <pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">&lt;part&gt;
    &lt;headers&gt;
      &lt;Content-Type&gt;image/jpeg&lt;/Content-Type&gt;
    &lt;headers&gt;
    &lt;options&gt;
      &lt;output-encoding&gt;...&lt;/output-encoding&gt;
      &lt;output-sgml-character-entities&gt;...&lt;/output-sgml-character-entities&gt;
    &lt;/options&gt;
  &lt;/part&gt;</pre>

  <p class="javascript" xmlns="http://www.w3.org/1999/xhtml">The manifest can also be defined as a JSON array.</p>
  <pre class="javascript" xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">[
    {
      "headers": {
        "Content-Type":"image/jpeg"
      },
      "options": {
       "outputEncoding": ...,
       "outputSgmlCharacterEntities" : ...
      }
    },
    {
      "headers": {
        "Content-Type":"text/html"
      }
    }
  ]</pre>

</api:summary><api:params><api:param name="separator" type="xs:string"><api:param-description>
    The string that is to be used as a separator.
  </api:param-description><api:param-name>separator</api:param-name><api:param-type>String</api:param-type></api:param><api:param class="javascript" name="manifest" type="Array|Node"><api:param-description>
    The manifest.
  </api:param-description><api:param-name>manifest</api:param-name><api:param-type>Array|Node</api:param-type></api:param><api:param class="javascript" name="content" type="Array|ValueIterator"><api:param-description>
    The nodes that are to be encoded.
  </api:param-description><api:param-name>content</api:param-name><api:param-type>Array|ValueIterator</api:param-type></api:param></api:params><api:return>binary()</api:return><api:usage>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var html = xdmp.unquote('&lt;html&gt;&lt;p&gt;Some stuff in an .html document&lt;/p&gt;&lt;/html&gt;')
                .next().value;
var xml = xdmp.unquote('&lt;root&gt; \n\
		          &lt;a&gt;Some other stuff in a .xml document&lt;/a&gt; \n\
			&lt;/root&gt;').next().value;
var json = xdmp.toJSON(["a",false]);
var boundaryString = "gc0p4Jq0M2Yt08jU534c0p";
var manifest = xdmp.unquote(
  '&lt;manifest&gt;'
+   '&lt;part&gt;&lt;headers&gt;'
+     '&lt;Content-Type&gt;application/xml&lt;/Content-Type&gt;'
+     '&lt;boundary&gt;gc0p4Jq0M2Yt08jU534c0p&lt;/boundary&gt;'
+      '&lt;/headers&gt;'
+    '&lt;/part&gt;'
+    '&lt;part&gt;&lt;headers&gt;&lt;Content-Type&gt;text/html&lt;/Content-Type&gt; &lt;/headers&gt;&lt;/part&gt; '
+    '&lt;part&gt;&lt;headers&gt;&lt;Content-Type&gt;application/json&lt;/Content-Type&gt;&lt;/headers&gt;&lt;/part&gt;'
+ '&lt;/manifest&gt;').next().value.root
xdmp.multipartEncode(
   boundaryString,
   manifest,
   [xml,html,json] )

=&gt;
--gc0p4Jq0M2Yt08jU534c0p
Content-Type: application/xml
boundary: gc0p4Jq0M2Yt08jU534c0p
Content-Length: 94

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;root&gt;&lt;a&gt;Some other stuff in a .xml document&lt;/a&gt;&lt;/root&gt;
--gc0p4Jq0M2Yt08jU534c0p
Content-Type: text/html
Content-Length: 90

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;html&gt;&lt;p&gt;Some stuff in an .html document&lt;/p&gt;&lt;/html&gt;
--gc0p4Jq0M2Yt08jU534c0p
Content-Type: application/json
Content-Length: 12

["a", false]
--gc0p4Jq0M2Yt08jU534c0p--

</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var html = xdmp.unquote('&lt;html&gt;&lt;p&gt;Some stuff in an .html document&lt;/p&gt;&lt;/html&gt;')
                .next().value;
var xml = xdmp.unquote('&lt;root&gt; \n\
              &lt;a&gt;Some other stuff in a .xml document&lt;/a&gt; \n\
      &lt;/root&gt;').next().value;
var json = xdmp.toJSON(["a",false]);
var boundaryString = "gc0p4Jq0M2Yt08jU534c0p";
var manifest_json = [
  {
    "headers": {
      "Content-Type":"application/xml",
      "boundary":"gc0p4Jq0M2Yt08jU534c0p"
    }
    ,
    "options": {
     "outputEncoding": "utf-8",
     "outputSgmlCharacterEntities" : false
    }
  },
  {
    "headers": {
      "Content-Type":"text/html"
    }
  },
    {
    "headers": {
      "Content-Type":"application/json"
    }
  }
]
xdmp.multipartEncode(
   boundaryString,
   manifest_json,
   [xml,html,json] )

</pre></api:example></api:function></api:function-page>