Tree navigation

With XSH2, it is possible to browse a document tree (XML data represented as a DOM-tree) as if it was a local filesystem, except that XPath expressions are used instead of ordinary directory paths.

To mimic the filesystem navigation as closely as possible, XSH2 contains several commands named by analogy of UNIX filesystem commands, such as cd, ls and pwd.

The current position in the document tree is called the current node. Current node's XPath may be queried with pwd command. In the interactive shell, current node is also displayed in the command line prompt. (Since there may be multiple document trees open at the same time, XSH2 tries to locate a variable holding the current document and use it to fully qualify current node's XPath in the XSH2 prompt.) Remember, that beside cd command, current node (and document) is also silently changed by open command, create command and temporarily also by the node-list variant of the foreach loop without a loop variable.

XPath expressions are always evaluated in context of the current node. Different documents can be accessed through variables: $doc/foo[1]/bar.

Example 2. XSH2 shell

$scratch:/> $docA := open "testA.xml"
$docA/> $docB := open "testB.xml"
$docB/> pwd
/
$docB/> cd $docA/article/chapter[title='Conclusion']
$docA/article/chapter[5]> pwd
/article/chapter[5]
$docA/article/chapter[5]> cd previous-sibling::chapter
$docA/article/chapter[4]> cd ..
$docA/article> cd $docB
$docB:/> ls
<?xml version="1.0" encoding="utf-8"?>
<article>...</article>

Related topics

canonical

serialize nodes as to canonical XML

cd

change current context node

fold

mark elements to be folded by list command

ls

list a given part of a document as XML

locate

show a given node location (as a canonical XPath)

pwd

show current context node location (as a canonical XPath)

register-function

define XPath extension function (EXPERIMENTAL)

unfold

unfold elements folded with fold command

unregister-function

undefine extension function (EXPERIMENTAL)

xpath

XPath expression