doc() and doc-available() load and test XML documents; collection() and uri-collection() return many documents or their URIs; unparsed-text(), unparsed-text-lines() and unparsed-text-available() read plain text such as CSV; environment-variable() reads the environment. Relative URIs resolve against the static base URI.
mkdir -p feeds && cp booknest-catalog.xml feeds/a.xml && cp booknest-catalog.xml feeds/b.xml
printf 'sku,price\nBN-0001,14.99\nBN-0003,26.00\n' > feeds/price-updates.csv
xp 'count(collection("feeds?select=*.xml")//book)' \
'unparsed-text-lines("feeds/price-updates.csv")[position() gt 1]'Output
count(collection("feeds?select=*.xml")//book) => 12
unparsed-text-lines("feeds/price-updates.csv")[position() gt 1] => "BN-0001,14.99"
"BN-0003,26.00"?select= is Saxon 726,956 's syntax (BaseX 693,830 maps collections to databases), so collection code is rarely portable. Writing and listing files needs the EXPath File module (file:write()), built into BaseX and in Saxon-PE and EE.
File Functions
File functions load external XML documents, plain-text files, and system environment variables into an XPath expression. Any filename passed to the functions below may be prefixed with http:// or file://, and a query string starting with ? can also be appended to a URL.| doc("data.xml") | Returns the document node for the file data.xml. Further node paths can be appended, e.g. doc("data.xml")//a returns all <a> nodes in the document. |
| doc-available("data.xml") | Returns true if data.xml exists and can be returned as a document node. |
| collection("s*.xml") | Returns a sequence of document nodes for files whose names start with s. |
| uri-collection("s*.xml") | Returns a sequence of URI strings, i.e. file names, for files whose names start with s. |
| unparsed-text("data.dat") | Returns a string representation of the content of the file data.dat. |
| unparsed-text-lines("data.dat") | Returns a sequence of strings, one per line of content in the file data.dat. |
| unparsed-text-available("data.dat") | Returns true if the file data.dat is available to be read by unparsed-text(). |
| environment-variable("APPDATA") | Returns the value of the system environment variable APPDATA. |
| available-environment-variables() | Returns a sequence of the names of the available system environment variables. |
merged-01-01-ch03-file-functions.xpath.txt
doc("data.xml")//a
doc-available("data.xml")
unparsed-text-lines("data.dat")
environment-variable("APPDATA")