<?xml version="1.0" encoding="UTF-8"?>
<fos:functions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ex="http://expath.org/ns/xmlspec"
    xmlns:fos="http://www.w3.org/xpath-functions/spec/namespace"
    xmlns:doc="http://jwlresearch.net/2012/doc"
    xsi:schemaLocation="http://www.w3.org/xpath-functions/spec/namespace fos.xsd">

   <fos:global-variables>
      <fos:variable id="v-expath-irrelevant" name="irrelevant" select="()"/>
   </fos:global-variables>

    <fos:function name="exists" prefix="file">
        <fos:signatures>
            <fos:proto name="exists" return-type="xs:boolean">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Tests if a file or directory exists.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns <code>true</code> if <code>$path</code> points to a file or directory,
                <code>false</code> otherwise.</p>
            <p>On UNIX-based systems the root and the volume roots are considered directories.</p>
        </fos:rules>
    </fos:function>

    <fos:function name="is-dir" prefix="file">
        <fos:signatures>
            <fos:proto name="is-dir" return-type="xs:boolean">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Tests if <code>$path</code> points to a directory.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns <code>true</code> if <code>$path</code> points to a directory,
                <code>false</code> otherwise.</p>
            <p>On UNIX-based systems the root and the volume roots are considered directories.</p>
        </fos:rules>
    </fos:function>

    <fos:function name="is-file" prefix="file">
        <fos:signatures>
            <fos:proto name="is-file" return-type="xs:boolean">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Tests if <code>$path</code> points to a file.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns <code>true</code> if <code>$path</code> points to a existing file.</p>
            <p>Returns <code>false</code> if <code>$path</code> points to a existing directory.</p>
            <p>Otherwise returns <code>false</code></p>
        </fos:rules>
    </fos:function>

    <fos:function name="last-modified" prefix="file">
        <fos:signatures>
            <fos:proto name="last-modified" return-type="xs:dateTime">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the last modification time of a file or directory.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the last modification time of a file or directory.</p>

        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="not-found"/> is raised if <code>$path</code> does not
                exist.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="size" prefix="file">
        <fos:signatures>
            <fos:proto name="size" return-type="xs:integer">
                <fos:arg type="xs:string" name="file"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the byte size of a file, or the value <code>0</code> for directories.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns <code>0</code> if <code>$file</code> points to a directory.</p>
            <p>Returns the byte size of the file <code>$file</code>, if it exists.</p>

        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="not-found"/> is raised if <code>$path</code> does not
                exist.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="append" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="append" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="item()*" name="items"/>
            </fos:proto>-->
            <fos:proto name="append" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="item()*" name="items"/>
                <fos:arg type="element(output:serialization-parameters)?" default="()" name="params"
                />
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Appends a sequence of items to a file. If the file pointed by <code>$file</code> does
                not exist, a new file will be created.</p>
        </fos:summary>
        <fos:rules>
            <p>Appends a sequence of items to a file.</p>
            <p>If the file pointed by <code>$file</code> does not exist, a new file will be
                created.</p>
            <p>
                <code>$params</code>, if not an empty sequence, controls the way the
                <code>$items</code> items are serialized. The semantics of <code>$params</code> are
                those of the same argument of <xspecref spec="FO40" ref="func-serialize"/>,
                consisting of an <code>output:serialization-parameters</code> element whose format
                is defined in <xspecref spec="SE40" ref="serparams-in-xdm-instance"/>. In contrast to <code>fn:serialize,</code> the
                encoding stage will not be skipped by this function.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>

        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$file</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="append-binary" prefix="file">
        <fos:signatures>
            <fos:proto name="append-binary" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:base64Binary" name="value"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Appends a Base64 item as binary data to a file.</p>
        </fos:summary>
        <fos:rules>
            <p>Appends a Base64 item as binary data to a file.</p>
            <p>If the file pointed to by <code>$file</code> does not exist, a new file will be
                created.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>

        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$file</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="append-text" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="append-text" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string" name="value"/>
            </fos:proto>-->
            <fos:proto name="append-text" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string" name="value"/>
                <fos:arg type="xs:string?" default="'utf-8'" name="encoding"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Appends a string to a file.</p>
        </fos:summary>
        <fos:rules>
            <p>Appends a string to the file <code>$file</code>.</p>
            <p>If the file pointed to by <code>$file</code> does not exist, a new file will be
                created.</p>
            <p>The optional parameter <code>$encoding</code>, if omitted or an empty sequence, is
                considered to be <code>UTF-8</code>.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>

        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$file</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="unknown-encoding"/> is raised if <code>$encoding</code>
                is invalid or not supported by the implementation.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="append-text-lines" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="append-text-lines" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string*" name="values"/>
            </fos:proto>-->
            <fos:proto name="append-text-lines" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string*" name="lines"/>
                <fos:arg type="xs:string?" default="'utf-8'" name="encoding"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Appends a sequence of strings to a file, each followed by the system-dependent
                newline character.</p>
        </fos:summary>
        <fos:rules>
            <p>Appends a sequence of strings to a file, each followed by the system-dependent
                newline character.</p>
            <p>If the file pointed to by <code>$file</code> does not exist, a new file will be
                created.</p>
            <p>The optional parameter <code>$encoding</code>, if omitted or an empty sequence, is
                considered to be <code>UTF-8</code>.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>

        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$file</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="unknown-encoding"/> is raised if <code>$encoding</code>
                is invalid or not supported by the implementation.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="copy" prefix="file">
        <fos:signatures>
            <fos:proto name="copy" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="source"/>
                <fos:arg type="xs:string" name="target"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Copies a file or a directory given a source and a target path/URI.</p>
        </fos:summary>
        <fos:rules>
            <p>Copies a file or a directory given a source and a target path/URI. The following
                cases may occur if <code>$source</code> points to a file:</p>
            <olist>
                <item>
                    <p> if <code>$target</code> does not exist, it will be created.</p>
                </item>
                <item>
                    <p> if <code>$target</code> is a file, it will be overwritten.</p>
                </item>
                <item>
                    <p> if <code>$target</code> is a directory, the file will be created in that
                        directory with the name of the source file. If a file already exists, it
                        will be overwritten.</p>
                </item>
            </olist>
            <p>The following cases may occur if <code>$source</code> points to a directory:</p>
            <olist>
                <item>
                    <p> if <code>$target</code> does not exist, it will be created as directory, and
                        all files of the source directory are copied to this directory with their
                        existing local names.</p>
                </item>
                <item>
                    <p> if <code>$target</code> is a directory, the source directory with all its
                        files will be copied into the target directory. At each level, if a file
                        already exists in the target with the same name as in the source, it is
                        overwritten. If a directory already exists in the target with the same name
                        as in the source, it is not removed, it is recursed in place (if it does not
                        exist, it is created before recursing).</p>
                </item>
            </olist>
            <p>Other cases will raise one of the errors listed below.</p>
            <p>The function returns the empty sequence if the operation is successful. If an error
                occurs during the operation, no rollback to the original state will be possible </p>

        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="not-found"/> is raised if the <code>$source</code> path
                does not exist.</p>
            <p><errorref spec="FILE40" code="exists"/> is raised if <code>$source</code> points to a
                directory and <code>$target</code> points to an existing file.</p>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$source</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$source</code> points to a
                file and <code>$target</code> points to a directory, in which a subdirectory exists
                with the name of the source file.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="create-dir" prefix="file">
        <fos:signatures>
            <fos:proto name="create-dir" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="dir"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Creates a directory if it does not already exist.</p>
        </fos:summary>
        <fos:rules>
            <p>Creates a directory, or does nothing if the directory already exists. The operation
                will create all non-existing parent directories.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="exists"/> is raised if the specified path, or any of
                its parent directories, points to an existing file.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="create-temp-dir" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="create-temp-dir" return-type="xs:string">
                <fos:arg type="xs:string" name="prefix"/>
                <fos:arg type="xs:string" name="suffix"/>
            </fos:proto>-->
            <fos:proto name="create-temp-dir" return-type="xs:string">
                <fos:arg type="xs:string" name="prefix"/>
                <fos:arg type="xs:string" name="suffix"/>
                <fos:arg type="xs:string?" default="()" name="dir"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Creates a temporary directory.</p>
        </fos:summary>
        <fos:rules>
            <p>Creates a temporary directory and all non-existing parent directories and returns the
                full path to the created directory.</p>
            <p>The temporary directory will not be automatically deleted after query execution. It
                is guaranteed to not already exist when the function is called.</p>
            <p>If <code>$dir</code> is omitted or an empty sequence, the directory will be created
                inside the system-dependent default temporary-file directory.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the specified directory does not
                exist or points to a file.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="create-temp-file" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="create-temp-file" return-type="xs:string">
                <fos:arg type="xs:string" name="prefix"/>
                <fos:arg type="xs:string" name="suffix"/>
            </fos:proto>-->
            <fos:proto name="create-temp-file" return-type="xs:string">
                <fos:arg type="xs:string" name="prefix"/>
                <fos:arg type="xs:string" name="suffix"/>
                <fos:arg type="xs:string?" default="()" name="dir"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Creates a temporary file.</p>
        </fos:summary>
        <fos:rules>
            <p>Creates a temporary file and all non-existing parent directories and returns the full
                path to the created file.</p>
            <p>The temporary file will not be automatically deleted after query execution. It is
                guaranteed to not already exist when the function is called.</p>
            <p>If <code>$dir</code> is omitted or an empty sequence, the file will be created inside
                the system-dependent default temporary-file directory.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the specified does not exist or
                points to a file.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="delete" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="delete" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>-->
            <fos:proto name="delete" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="path"/>
                <fos:arg type="xs:boolean?" default="false()" name="recursive"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Deletes a file or a directory from the file system.</p>
        </fos:summary>
        <fos:rules>
            <p>Deletes a file or a directory from the file system.</p>
            <p>If the optional parameter <code>$recursive</code> is <code>true</code>,
                sub-directories will be deleted as well.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="not-found"/> is raised if <code>$path</code> does not
                exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                non-empty directory.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="list" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="list" return-type="xs:string*">
                <fos:arg type="xs:string" name="dir"/>
            </fos:proto>
            <fos:proto name="list" return-type="xs:string*">
                <fos:arg type="xs:string" name="dir"/>
                <fos:arg type="xs:boolean" name="recursive"/>
            </fos:proto>-->
            <fos:proto name="list" return-type="xs:string*">
                <fos:arg type="xs:string" name="dir"/>
                <fos:arg type="xs:boolean?" default="false()" name="recursive"/>
                <fos:arg type="xs:string?" default="()" name="pattern"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Lists all files and directories in a given directory.</p>
        </fos:summary>
        <fos:rules>
            <p>Lists all files and directories in a given directory. The order of the items in the
                resulting sequence is not defined. The "." and ".." items are never returned. The
                returned paths are relative to the provided directory <code>$dir</code>.</p>
            <p>If the optional parameter <code>$recursive</code> is <code>true</code>, all
                directories and files will be returned that are found while recursively traversing
                the given directory. If <code>$recursive</code> is omitted or an empty sequence or
                <code>false</code> only the contents of the specified directory will be returned. </p>
            <p>The optional <code>$pattern</code> parameter defines a name pattern in the glob
                syntax. If this is provided and is not an empty sequence, only the paths of the
                files and directories whose names are matching the pattern will be returned.</p>
            <p>An implementation must support at least the following glob syntax for the pattern: <ulist>
                    <item>
                        <p>
                            <code>*</code> for matching any number of unknown characters
                        and</p></item>
                    <item>
                        <p><code>?</code> for matching one unknown character.</p></item>
                </ulist>
            </p>
            <p>A related function is <code>file:children</code>.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if <code>$dir</code> does not point
                to an existing directory.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
        <fos:examples>
           <fos:example>
              <fos:test spec="XQuery">
                 <fos:expression>list(.))</fos:expression>
                 <fos:result>not(empty(.))</fos:result>
              </fos:test>
           </fos:example>
        </fos:examples>
    </fos:function>

    <fos:function name="move" prefix="file">
        <fos:signatures>
            <fos:proto name="move" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="source"/>
                <fos:arg type="xs:string" name="target"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Moves a file or a directory.</p>
        </fos:summary>
        <fos:rules>
            <p>Moves a file or a directory given a source and a target path/URI. The following cases
                may occur if <code>$source</code> points to a file:</p>
            <olist>
                <item>
                    <p> if <code>$target</code> does not exist, it will be created.</p>
                </item>
                <item>
                    <p> if <code>$target</code> is a file, it will be overwritten.</p>
                </item>
                <item>
                    <p> if <code>$target</code> is a directory, the file will be created in that
                        directory with the name of the source file. If a file already exists, it
                        will be overwritten.</p>
                </item>
            </olist>
            <p>The following cases may occur if <code>$source</code> points to a directory:</p>
            <olist>
                <item>
                    <p> if <code>$target</code> does not exist, it will be created as directory, and
                        all files of the source directory are moved to this directory with their
                        existing local names.</p>
                </item>
                <item>
                    <p> if <code>$target</code> is a directory, the source directory with all its
                        files will be moved into the target directory. If the target directory
                        contains a directory with the same name as the source, the error <errorref
                            spec="FILE40" code="is-dir"/> is raised.</p>
                </item>
            </olist>
            <p>Other cases will raise one of the errors listed below.</p>
            <p>The function returns the empty sequence if the operation is successful. If an error
                occurs during the operation, no rollback to the original state will be possible </p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="not-found"/> is raised if the <code>$source</code> path
                does not exist.</p>
            <p><errorref spec="FILE40" code="exists"/> is raised if <code>$source</code> points to a
                directory and <code>$target</code> points to an existing file.</p>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$source</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$target</code> points to a
                directory, in which a subdirectory exists with the name of the source.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="read-binary" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="read-binary" return-type="xs:base64Binary">
                <fos:arg type="xs:string" name="file"/>
            </fos:proto>
            <fos:proto name="read-binary" return-type="xs:base64Binary">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:integer" name="offset"/>
            </fos:proto>-->
            <fos:proto name="read-binary" return-type="xs:base64Binary">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:integer?" default="0" name="offset"/>
                <fos:arg type="xs:integer?" default="()" name="length"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the content of a file in its Base64 representation.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the content of a file in its Base64 representation.</p>
            <p>The optional parameters <code>$offset</code> and <code>$length</code> can be used to
                read chunks of a file.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="not-found"/> is raised if <code>$file</code> does not
                exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="out-of-range"/> is raised if <code>$offset</code> or
                <code>$length</code> is negative, or if the chosen values would exceed the file
                bounds.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="read-text" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="read-text" return-type="xs:string">
                <fos:arg type="xs:string" name="file"/>
            </fos:proto>-->
            <fos:proto name="read-text" return-type="xs:string">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string?" default="'utf-8'" name="encoding"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the content of a file in its string representation.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the content of a file in its string representation.</p>
            <p>The optional parameter <code>$encoding</code>, if omitted or an empty sequence, is
                considered to be <code>UTF-8</code>.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="not-found"/> is raised if <code>$file</code> does not
                exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="unknown-encoding"/> is raised if <code>$encoding</code>
                is invalid or not supported by the implementation.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="read-text-lines" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="read-text-lines" return-type="xs:string*">
                <fos:arg type="xs:string" name="file"/>
            </fos:proto>-->
            <fos:proto name="read-text-lines" return-type="xs:string*">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string?" default="'utf-8'" name="encoding"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the contents of a file as a sequence of strings, separated at newline
                boundaries.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the contents of a file as a sequence of strings, separated at newline
                boundaries.</p>
            <p>The optional parameter <code>$encoding</code>, if omitted or an empty sequence, is
                considered to be <code>UTF-8</code>.</p>
            <p>The newline handling is the same as for <xspecref spec="FO40"
                    ref="func-unparsed-text-lines"/>.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="not-found"/> is raised if <code>$file</code> does not
                exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="unknown-encoding"/> is raised if <code>$encoding</code>
                is invalid or not supported by the implementation.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="write" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="write" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="item()*" name="items"/>
            </fos:proto>-->
            <fos:proto name="write" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="item()*" name="items"/>
                <fos:arg type="element(output:serialization-parameters)?" default="()" name="params"
                />
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Writes a sequence of items to a file.</p>
        </fos:summary>
        <fos:rules>
            <p>Writes a sequence of items to a file.</p>
            <p> If <code>$file</code> already exists, it will be overwritten; otherwise, it will be
                created.</p>
            <p>
                <code>$params</code>, if not an empty sequence, controls the way the
                <code>$items</code> items are serialized. The semantics of <code>$params</code> are
                those of the same argument of <xspecref spec="FO40" ref="func-serialize"/>,
                consisting of an <code>output:serialization-parameters</code> element whose format
                is defined in <xspecref spec="SE40" ref="serparams-in-xdm-instance"/>. In contrast to <code>fn:serialize</code>, the encoding stage will not
                be skipped by this function.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>

        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$file</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="write-binary" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="write-binary" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:base64Binary" name="value"/>
            </fos:proto>-->
            <fos:proto name="write-binary" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:base64Binary" name="value"/>
                <fos:arg type="xs:integer?" default="0" name="offset"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Writes a Base64 item as binary to a file.</p>
        </fos:summary>
        <fos:rules>
            <p>Writes a Base64 item as binary to a file. </p>
            <p>If <code>$file</code> already exists, it will be overwritten; otherwise, it will be
                created.</p>
            <p>If the optional parameter <code>$offset</code> is specified and not set to an empty
                sequence, data will be written starting at this file position. An existing file may
                be resized by such an operation.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$file</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="out-of-range"/> is raised if <code>$offset</code> is
                negative, or if it exceeds the current file size.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="write-text" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="write-text" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string" name="value"/>
            </fos:proto>-->
            <fos:proto name="write-text" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string" name="value"/>
                <fos:arg type="xs:string?" default="'utf-8'" name="encoding"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Writes a string to a file.</p>
        </fos:summary>
        <fos:rules>
            <p>Writes a strings to a file.</p>
            <p> If <code>$file</code> already exists, it will be overwritten.</p>
            <p>The optional parameter <code>$encoding</code>, if omitted or an empty sequence, is
                considered to be <code>UTF-8</code>.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$file</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="unknown-encoding"/> is raised if <code>$encoding</code>
                is invalid or not supported by the implementation.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="write-text-lines" prefix="file">
        <fos:signatures>
            <!--<fos:proto name="write-text-lines" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string*" name="values"/>
            </fos:proto>-->
            <fos:proto name="write-text-lines" return-type="empty-sequence()">
                <fos:arg type="xs:string" name="file"/>
                <fos:arg type="xs:string*" name="values"/>
                <fos:arg type="xs:string?" default="'utf-8'" name="encoding"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Writes a sequence of strings to a file, each followed by the system-dependent newline
                character.</p>
        </fos:summary>
        <fos:rules>
            <p>Writes a sequence of strings to a file, each followed by the system-dependent newline
                character.</p>
            <p> If <code>$file</code> already exists, it will be overwritten; otherwise, it will be
                created.</p>
            <p>The optional parameter <code>$encoding</code>, if omitted or an empty sequence, is
                considered to be <code>UTF-8</code>.</p>
            <p>The function returns the empty sequence if the operation is successful.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if the parent directory of
                <code>$file</code> does not exist.</p>
            <p><errorref spec="FILE40" code="is-dir"/> is raised if <code>$file</code> points to a
                directory.</p>
            <p><errorref spec="FILE40" code="unknown-encoding"/> is raised if <code>$encoding</code>
                is invalid or not supported by the implementation.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="name" prefix="file">
        <fos:signatures>
            <fos:proto name="name" return-type="xs:string">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>deterministic</fos:property>
            <fos:property>context-independent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the name of a file or directory.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the name of a file or directory.</p>
            <p>An empty string is returned if the path points to the root directory, or if it
                contains no directory separators.</p>
            <p>This function is <xtermref spec="FO40" ref="dt-deterministic"
                    >deterministic</xtermref> (no path existence check is made).</p>
        </fos:rules>
    </fos:function>

    <fos:function name="parent" prefix="file">
        <fos:signatures>
            <fos:proto name="parent" return-type="xs:string?">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the parent directory of a given path.</p>
        </fos:summary>
        <fos:rules>
            <p>Transforms the given path into an absolute path, as specified by <loc
                    href="#fn.resolve-path">file:resolve-path</loc>, and returns the parent
                directory.</p>
            <p>The inverse function is <loc href="#fn.children">file:children</loc>.</p>
            <p>An empty sequence is returned if the path points to a root directory.</p>
        </fos:rules>
    </fos:function>

    <fos:function name="children" prefix="file">
        <fos:signatures>
            <fos:proto name="children" return-type="xs:string*">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the paths of all files and directories that are located in the given
                directory.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the paths of all files and directories that are located in the given
                directory. The order of the items in the resulting sequence is not defined. The "."
                and ".." items are never returned.</p>
            <p>The inverse function is <loc href="#fn.parent">file:parent</loc>; a related function
                is <loc href="#fn.list">file:list</loc>.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="no-dir"/> is raised if <code>$path</code> does not
                point to an existing directory.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if any other error occurs.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="path-to-native" prefix="file">
        <fos:signatures>
            <fos:proto name="path-to-native" return-type="xs:string">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Transforms a URI, an absolute path, or relative path to a canonical, system-dependent
                path representation.</p>
        </fos:summary>
        <fos:rules>
            <p>Transforms a URI, an absolute path, or relative path to a canonical, system-dependent
                path representation. A canonical path is both absolute and unique and thus contains
                no redirections such as references to parent directories or symbolic links.</p>
            <p>If the resulting path points to a directory, it will be suffixed with the
                system-specific directory separator.</p>
        </fos:rules>
        <fos:errors>
            <p><errorref spec="FILE40" code="not-found"/> is raised if <code>$path</code> does not
                exist.</p>
            <p><errorref spec="FILE40" code="io-error"/> is raised if an error occurs while trying
                to obtain the native path.</p>
        </fos:errors>
    </fos:function>

    <fos:function name="path-to-uri" prefix="file">
        <fos:signatures>
            <fos:proto name="path-to-uri" return-type="xs:anyURI">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>deterministic</fos:property>
            <fos:property>context-independent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Transforms a file system path into a URI.</p>
        </fos:summary>
        <fos:rules>
            <p>Transforms a file system path into a URI with the <code>file://</code> scheme. If the
                path is relative, it is first resolved against the current working directory.</p>
            <p>This function is <xtermref spec="FO40" ref="dt-deterministic"
                    >deterministic</xtermref> (no path existence check is made).</p>
        </fos:rules>
    </fos:function>

    <fos:function name="resolve-path" prefix="file">
        <fos:signatures>
            <fos:proto name="resolve-path" return-type="xs:string">
                <fos:arg type="xs:string" name="path"/>
            </fos:proto>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Transforms a relative path into an absolute operating system path.</p>
        </fos:summary>
        <fos:rules>
            <p>Transforms a relative path into an absolute operating system path by resolving it
                against the current working directory.</p>
            <p>If the resulting path points to a directory, it will be suffixed with the
                system-specific directory separator.</p>
        </fos:rules>
    </fos:function>

    <fos:function name="dir-separator" prefix="file">
        <fos:signatures>
            <fos:proto name="dir-separator" return-type="xs:string"/>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the value of the operating system-specific directory separator.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the value of the operating system-specific directory separator, which usually
                is <code>/</code> on UNIX-based systems and <code>\</code> on Windows systems.</p>
        </fos:rules>
    </fos:function>

    <fos:function name="line-separator" prefix="file">
        <fos:signatures>
            <fos:proto name="line-separator" return-type="xs:string"/>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the value of the operating system-specific line separator.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the value of the operating system-specific line separator, which usually is
                <code>&amp;#10;</code> on UNIX-based systems, <code>&amp;#13;&amp;#10;</code> on
                Windows systems and <code>&amp;#13;</code> on Mac systems.</p>
        </fos:rules>
    </fos:function>

    <fos:function name="path-separator" prefix="file">
        <fos:signatures>
            <fos:proto name="path-separator" return-type="xs:string"/>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the value of the operating system-specific path separator.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the value of the operating system-specific path separator, which usually is
                <code>:</code> on UNIX-based systems and <code>;</code> on Windows systems.</p>
        </fos:rules>
    </fos:function>

    <fos:function name="temp-dir" prefix="file">
        <fos:signatures>
            <fos:proto name="temp-dir" return-type="xs:string"/>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the path to the default temporary-file directory of an operating system.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the path to the default temporary-file directory of an operating system.</p>
        </fos:rules>
    </fos:function>

    <fos:function name="base-dir" prefix="file">
        <fos:signatures>
            <fos:proto name="base-dir" return-type="xs:string?"/>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the parent directory of the static base URI.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the parent directory of the static base URI.</p>
            <p>If the Base URI property is undefined, the empty sequence is returned.</p>
            <p>If a static base URI exists, and if points to a local file path, this function
                returns the same result as the expression
                <code>file:parent(static-base-uri())</code>.</p>
        </fos:rules>
    </fos:function>

    <fos:function name="current-dir" prefix="file">
        <fos:signatures>
            <fos:proto name="current-dir" return-type="xs:string"/>
        </fos:signatures>
        <fos:properties>
            <fos:property>nondeterministic</fos:property>
            <fos:property>context-dependent</fos:property>
            <fos:property>focus-independent</fos:property>
        </fos:properties>
        <fos:summary>
            <p>Returns the current working directory.</p>
        </fos:summary>
        <fos:rules>
            <p>Returns the current working directory.</p>
        </fos:rules>
        <fos:equivalent style="xpath-expression" covers-error-cases="true">
            file:resolve-path('.')</fos:equivalent>
    </fos:function>

</fos:functions>
