document() Function (SLAX)
Namespaces
http://xml.libslax.org/slax
SLAX Syntax
string slax:document(url, <options>)
Description
Read data from a file or URL. Optional arguments specify the character encoding scheme and the encoding format and define the replacement string for non-XML control characters.
The slax:document()
function reads text from the specified file and
returns a string containing that text. The data can be encoded in any character set
and can be BASE64 encoded. The default character set is "utf‑8". You can set the
format
option to "base64" to decode base64-encoded files.
After you read the data, you can convert the data in the string into a more useful
format. For example, you can use the xutil:string-to-xml()
or
xutil:json-to-xml()
libslax function to convert the data in the
string into the native representation of that data in XML. For more information
about the libslax xutil
library, see libslax Default Extension Libraries: bit, curl, db, os, and xutil.
XML cannot represent control characters. If a file contains control characters, the
slax:document()
function removes the control characters by
default. Automatically removing the control characters enables you to convert the
data in the string to XML. Alternatively, instead of removing the control
characters, you can include the non-xml
option to replace the
characters with a single string.
Calling the slax:document()
function to read the same file
multiple times within a script does not reflect any changes made to that file in
the interim, because the file is cached when first read, and the original
contents are returned every time the slax:document()
function
retrieves the same file.
Parameters
options |
(Optional) Specify the character encoding scheme and format of the data, and define the replacement string for non-XML control characters.
|
||||||||
url |
File or URL from which to read data. |
Return Value
string | String representing the data. |
Usage Examples
var $data = slax:document($url); var $options := { <encoding> "ascii"; <format> "base64"; <non-xml> "#"; } var $data2 = slax:document($url, $options);
Release Information
Function introduced in version 1.1 of the SLAX language, which is supported in Junos OS Release 12.2 and later releases.