<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.save.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.save</api:function-name><api:suggest>xdmp.save</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>save</api:suggest><api:function-link mode="xquery" fullname="xdmp:save">/apidoc/8.0/xdmp:save.xml</api:function-link><api:function mode="javascript" name="save" type="builtin" lib="xdmp" category="UpdateBuiltins" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.save"><api:summary>
  Serializes a node as text and saves it to a file. The node can be any
  node, including a document node, an element node, a text node, or a binary
  node.
</api:summary><api:params><api:param name="path" type="xs:string"><api:param-description>
    The output file pathname. The path can be fully qualifed or relative.
    Relative pathnames are resolved from the directory in which
    MarkLogic Server is installed.
  </api:param-description><api:param-name>path</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="node" type="node()"><api:param-description>
    The node to be serialized.
  </api:param-description><api:param-name>node</api:param-name><api:param-type>Node</api:param-type></api:param><api:param name="options" type="(element()|map:map)?" optional="true"><api:param-description>

    The options 
    <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">object</span> for this save operation. 
    The default value is
    <code xmlns="http://www.w3.org/1999/xhtml">
    <span class="javascript">null</span></code>.
    
    <p xmlns="http://www.w3.org/1999/xhtml">The
    <code>
    <span class="javascript">xdmp.save</span></code> options include:</p>
    <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
      <dt><p>
	
      <span class="javascript">outputEncoding</span></p></dt>
      <dd>Specifies the encoding to use when saving the document.</dd>
      <dt><p>
	
      <span class="javascript">outputSgmlCharacterEntities</span></p></dt>
      <dd>Specifies if character entities should be output upon serialization
      of the XML.  Valid values are <code>normal</code>, <code>none</code>,
      <code>math</code>, and <code>pub</code>. By default (that is, if this
      option is not specified), no SGML entities are serialized on output, 
      unless the App Server is configured to output SGML character 
      entities.</dd>
      <dt><p>
	
      <span class="javascript">method</span></p></dt>
      <dd>Valid values are <code>xml</code>, <code>html</code>,
      <code>xhtml</code>, and <code>text</code>.

      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">cdataSectionElements</span></p></dt>
      <dd>A 
      <span class="javascript">single QName or array of</span> QNames to output 
      as CDATA sections. This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>

      <dt><p>
	
      <span class="javascript">encoding</span></p></dt>
      <dd>The encoding.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>

      <dt><p>
	
      <span class="javascript">useCharacterMaps</span></p></dt>
      <dd>One or more of the following values, 
      <span class="javascript">as a string or an array of strings.</span>

      Valid values are <code>xdmp:sgml-entities-normal</code>,
      <code>xdmp:sgml-entities-math</code>, and
      <code>xdmp:sgml-entities-pub</code>. This is like the corresponding 
      part of both the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">mediaType</span></p></dt>
      <dd>A mimetype representing a media type. For example,
      <code>text/plain</code> or <code>application/xml</code> (or other 
      valid mimetypes).
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">byteOrderMark</span></p></dt>
      <dd>Valid values are <code>yes</code> or <code>no</code>.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">indent</span></p></dt>
      <dd>Specifies if typed XML (that is, XML for which there is an
      in-scope schema) should be pretty-printed (indented).  Valid
      values are <code>yes</code> or <code>no</code>.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">indentUntyped</span></p></dt>
      <dd>Specifies if untyped XML (that is, XML for which there is no
      in-scope schema) should be pretty-printed (indented).  Valid
      values are <code>yes</code> or <code>no</code>.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">indentTabs</span></p></dt>
      <dd>Specifies if tab characters should be used instead of 8 consecutive
      spaces when indenting.  Valid values are <code>yes</code> or <code>no</code>.
      </dd>
      <dt><p>
	
      <span class="javascript">includeContentType</span></p></dt>
      <dd>Include the content-type declaration when serializing the node.
      Valid values are
      <code>yes</code> or <code>no</code>.</dd>
      <dt><p>
	
      <span class="javascript">escapeUriAttributes</span></p></dt>
      <dd>Valid values are <code>yes</code> or <code>no</code>.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">doctypePublic</span></p></dt>
      <dd>A public identifier, which is the public identifier to use on the
      emitted DOCTYPE.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">doctypeSystem</span></p></dt>
      <dd>A system identifier, which is the system identifier to use on the
      emitted DOCTYPE.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">omitXmlDeclaration</span></p></dt>
      <dd>Valid values are <code>yes</code> or <code>no</code>.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">standalone</span></p></dt>
      <dd>Valid values are <code>yes</code> or <code>no</code>.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">normalizationForm</span></p></dt>
      <dd>Valid values are <code>NFC</code>, <code>NFD</code>,
      and <code>NFKD</code>.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
      <dt><p>
	
      <span class="javascript">defaultAttributes</span></p></dt>
      <dd>Specifies whether attributes defaulted with a schema should be
      included in the serialization.
      Valid values are <code>yes</code> or <code>no</code>.
      This is like the corresponding part of both
      the XSLT <a href="http://www.w3.org/TR/xslt20/#serialization">
      <code>xsl:output</code></a> instruction and the MarkLogic XQuery
      <code>xdmp:output</code> prolog statement.
      </dd>
    </dl></blockquote>

  </api:param-description><api:param-name>options</api:param-name><api:param-type>Object?</api:param-type></api:param></api:params><api:return>null</api:return><api:privilege>
  <p xmlns="http://www.w3.org/1999/xhtml"><code>http://marklogic.com/xdmp/privileges/xdmp-save</code></p>
</api:privilege><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
// serialize a JSON document in the database to a file on disk 
var json = fn.doc("/mydocs/example.json");
for (var x of json) {
xdmp.save("/space/hello.txt", x);
};
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
// save a text file 
var textnode = xdmp.toJSON("hello");
xdmp.save("/space/hello.txt", textnode);
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
// save a text document stored in the database to 
// disk, explicitly specifying the output encoding 
var txt = fn.doc("/mydocs/stuff.txt");
var options = {"outputEncoding": "utf-8"};
for (var x of txt) {
xdmp.save("mystuff.txt", x, options);
};
</pre></api:example></api:function></api:function-page>