Loading TOC...

xdmp.save

xdmp.save(
   $path as String,
   $node as Node,
   [$options as Object?]
) as null

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.

Parameters
$path 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.
$node The node to be serialized.
$options The options object for this save operation. The default value is null.

The xdmp.save options include:

outputEncoding

Specifies the encoding to use when saving the document.

outputSgmlCharacterEntities

Specifies if character entities should be output upon serialization of the XML. Valid values are normal, none, math, and pub. 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.

method

Valid values are xml, html, xhtml, and text. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

cdataSectionElements

A single QName or array of QNames to output as CDATA sections. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

encoding

The encoding. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

useCharacterMaps

One or more of the following values, as a string or an array of strings. Valid values are xdmp:sgml-entities-normal, xdmp:sgml-entities-math, and xdmp:sgml-entities-pub. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

mediaType

A mimetype representing a media type. For example, text/plain or application/xml (or other valid mimetypes). This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

byteOrderMark

Valid values are yes or no. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

indent

Specifies if typed XML (that is, XML for which there is an in-scope schema) should be pretty-printed (indented). Valid values are yes or no. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

indentUntyped

Specifies if untyped XML (that is, XML for which there is no in-scope schema) should be pretty-printed (indented). Valid values are yes or no. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

indentTabs

Specifies if tab characters should be used instead of 8 consecutive spaces when indenting. Valid values are yes or no.

includeContentType

Include the content-type declaration when serializing the node. Valid values are yes or no.

escapeUriAttributes

Valid values are yes or no. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

doctypePublic

A public identifier, which is the public identifier to use on the emitted DOCTYPE. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

doctypeSystem

A system identifier, which is the system identifier to use on the emitted DOCTYPE. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

omitXmlDeclaration

Valid values are yes or no. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

standalone

Valid values are yes or no. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

normalizationForm

Valid values are NFC, NFD, and NFKD. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

defaultAttributes

Specifies whether attributes defaulted with a schema should be included in the serialization. Valid values are yes or no. This is like the corresponding part of both the XSLT xsl:output instruction and the MarkLogic XQuery xdmp:output prolog statement.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-save

Example

// 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);
};

Example

// save a text file
var textnode = xdmp.toJSON("hello");
xdmp.save("/space/hello.txt", textnode);

Example

// 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);
};

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy