Files/Documents

XSH2 is designed as an environment for querying and manipulating XML and HTML documents. Use open or create commands to load an XML or HTML document from a local file, external URL (such as http:// or ftp://), string or pipe. XSH2 can optionally validate the document during parse process (see validation and load-ext-dtd). Parsed documents are stored in memory as DOM trees, that can be navigated and manipulated with XSH2 commands and XPath language, whose names and syntax make working with the DOM tree a flavor of working in a UNIX filesystem.

A parsed document is usually stored in a variable. XSH2 shares variables with the XPath engine, so if e.g. $doc is a XSH2 variable holding a document (or, more generally any node-set), then $doc//section/title is an XPath expression selecting all title subelements of all section elements within the (sub)tree of $doc.

Although XSH2 is able to parse remote documents via http:// or ftp://, it is only able to save them locally. To upload a document to a remote server (e.g. using FTP) or to store it into a database, use save command with a --pipe parameter, in connection with an external program able to store its standard input (XML) to the desired location. You can also use similar parameter with open in order to parse documents from standard output of some external program.

Example 1. Store a XSH2 document on a remote machine using the Secure Shell

xsh> save --pipe "ssh my.remote.org 'cat > test.xml'" $doc

Related topics

backups

turn on backup file creation

catalog

use a catalog file during all parsing processes

switch-to-new-documents

set on/off changing current document to newly open/created files

clone

clone a given document

close

close document (without saving)

create

make a new document from a given XML fragment

document

specifying documents

filename

specifying filenames

documents

display a list of open documents

index

index a static document for faster XPath lookup

nobackups

turn off backup file creation

nodename

specifying names of DOM nodes

open

load an XML, HTML, or Docbook SGML document from a file, pipe or URI

process-xinclude

load and insert XInclude sections

save

save a document as XML or HTML

set_filename

change filename or URL associated with a document

stream

process selected elements from an XML stream (EXPERIMENTAL)

subroutine

name of a sub-routine

$variable