MarkLogic Server 11.0 Product Documentation
xdmp:savexdmp:save(
$path as xs:string,
$node as node(),
[$options as (element()|map:map)?]
) as empty-sequence()
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 qualified or relative.
Relative pathnames are resolved from the directory in which
MarkLogic Server is installed.
|
node |
The node to be serialized.
|
options |
Options with which to customize this operation. You
can specify options as either an options XML element
in the "xdmp:save" namespace, or as a map:map . The
options names below are XML element localnames. When using a map,
replace the hyphens with camel casing. For example, "an-option"
becomes "anOption" when used as a map:map key.
This function supports the following options:
- output-encoding
- Specifies the encoding to use when saving the document.
- output-sgml-character-entities
- 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.
- cdata-section-elements
- A list of space-separated
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.
- use-character-maps
- One or more of the following values,
separated by spaces.
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.
- media-type
- 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.
- byte-order-mark
- 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.
- indent-untyped
- 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.
- indent-tabs
- Specifies if tab characters should be used instead of 8 consecutive
spaces when indenting. Valid values are
yes or
no .
- include-content-type
- Include the content-type declaration when serializing the node.
Valid values are
yes or no .
- escape-uri-attributes
- 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.
- doctype-public
- 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.
- doctype-system
- 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.
- omit-xml-declaration
- 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.
- normalization-form
- 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.
- default-attributes
- 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 an XML document in the database to a file on disk :)
let $mynode := doc("/mydocs/example.xml")
return xdmp:save("hello.txt", $text)
Example
(: save a text file :)
let $text := text { "hello" }
return xdmp:save("hello.txt", $text)
Example
(: save a text document stored in the database to
disk, explicitly specifying the output encoding :)
let $pdf := doc("/mydocs/stuff.pdf")
return
xdmp:save("mystuff.txt", $txt,
<options xmlns="xdmp:save">
<output-encoding>utf-8</output-encoding>
</options>)
Example
(: save a text document stored in the database to
disk, explicitly specifying the output encoding :)
let $txt := doc("/mydocs/stuff.txt")
return
xdmp:save("mystuff.txt", $txt,
map:map() => map:with("outputEncoding", "utf-8"))
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.