XML-XSH2

 view release on metacpan or  search on metacpan

lib/XML/XSH2/Help.pm  view on Meta::CPAN


  Within the interactive shell, press <TAB> for auto-completion.
END

$HELP{'toc'}=[<<'END'];

Help items:
-----------

  toc - this page

  XSH Language Topics:

    Argtypes - Argument Types
    Configuration - Global settings
    Documents - Files/Documents
    Flow - Flow control
    Information - Retrieving more information
    Manipulation - Tree modification
    Namespaces - Namespaces in XML and XPath
    Navigation - Tree navigation
    Perl_shell - Interacting with Perl and Shell
    Prompt - Prompt in the interactive shell
    Redirection - Command output redirection
    Variables - Variables
    xsh2delta - Changes since XSH 1.x

  XSH Commands:

    apropos, assign, backups, call, canonical, catalog, cd,
    change-ns-prefix, change-ns-uri, clone, close, copy, count, create,
    debug, declare-ns, def, defs, do, doc-info, documents, dtd, edit,
    edit-string, empty-tags, enc, encoding, eval, exec, exit, fold,
    foreach, get, hash, help, if, ifinclude, include, indent, index,
    insert, iterate, keep-blanks, last, lcd, lineno, load-ext-dtd, local,
    locate, ls, map, move, my, namespaces, next, nobackups, nodebug,
    normalize, open, parser-completes-attributes, parser-expands-entities,
    parser-expands-xinclude, pedantic-parser, perl, prev, print,
    process-xinclude, pwd, query-encoding, quiet, recovering, redo,
    register-function, register-namespace, register-xhtml-namespace,
    register-xsh-namespace, remove, rename, return, run-mode, save, set,
    set-dtd, set-enc, set-ns, set-standalone, set_filename, settings,
    skip-dtd, sort, stream, strip-whitespace, switch-to-new-documents,
    test-mode, throw, try, undef, unfold, unless, unregister-function,
    unregister-namespace, validate, validation, variables, verbose,
    version, while, wrap, wrap-span, xcopy, xinsert, xmove,
    xpath-axis-completion, xpath-completion, xpath-extensions, xslt,
    xupdate

  XSH Argument Types:

    $variable, block, command, document, encoding, expression, filename,
    location, node-type, nodename, perl-code, subroutine, xpath

  XPath Extension Functions:

    xsh:base-uri, xsh:context, xsh:current, xsh:doc, xsh:document,
    xsh:document-uri, xsh:documents, xsh:evaluate, xsh:filename, xsh:grep,
    xsh:id2, xsh:if, xsh:join, xsh:lc, xsh:lcfirst, xsh:lineno, xsh:lookup,
    xsh:map, xsh:match, xsh:matches, xsh:max, xsh:min, xsh:new-attribute,
    xsh:new-cdata, xsh:new-chunk, xsh:new-comment, xsh:new-element,
    xsh:new-element-ns, xsh:new-pi, xsh:new-text, xsh:parse, xsh:path,
    xsh:resolve-uri, xsh:reverse, xsh:same, xsh:serialize, xsh:span,
    xsh:split, xsh:sprintf, xsh:strmax, xsh:strmin, xsh:subst, xsh:substr,
    xsh:sum, xsh:times, xsh:uc, xsh:ucfirst, xsh:var

END

$HELP{'command'}=[<<'END'];
command

description:
	     XSH2 command consists of a command name and possibly command
	     parameters separated by whitespace. Individual [XSH2 commands]
	     are separated with a semicolon. A command may optionally be
	     followed by an output redirection directive (see
	     [binding_shell] for output redirection to a command and
	     [Variables] for output redirection to variable). Most commands
	     have aliases, so for example [remove] command may also be
	     invoked as 'del' or 'rm'.

	     XSH2 recognizes the following commands (not including
	     aliases): apropos, assign, backups, call, canonical, catalog,
	     cd, change-ns-prefix, change-ns-uri, clone, close, copy,
	     count, create, debug, declare-ns, def, defs, do, doc-info,
	     documents, dtd, edit, edit-string, empty-tags, enc, encoding,
	     eval, exec, exit, fold, foreach, get, hash, help, if,
	     ifinclude, include, indent, index, insert, iterate,
	     keep-blanks, last, lcd, lineno, load-ext-dtd, local, locate,
	     ls, map, move, my, namespaces, next, nobackups, nodebug,
	     normalize, open, parser-completes-attributes,
	     parser-expands-entities, parser-expands-xinclude,
	     pedantic-parser, perl, prev, print, process-xinclude, pwd,
	     query-encoding, quiet, recovering, redo, register-function,
	     register-namespace, register-xhtml-namespace,
	     register-xsh-namespace, remove, rename, return, run-mode,
	     save, set, set-dtd, set-enc, set-ns, set-standalone,
	     set_filename, settings, skip-dtd, sort, stream,
	     strip-whitespace, switch-to-new-documents, test-mode, throw,
	     try, undef, unfold, unless, unregister-function,
	     unregister-namespace, validate, validation, variables,
	     verbose, version, while, wrap, wrap-span, xcopy, xinsert,
	     xmove, xpath-axis-completion, xpath-completion,
	     xpath-extensions, xslt, xupdate

see also:     block

END


$HELP{'block'}=[<<'END'];
block argument type

description:
	     a block of semicolon-separated XSH2 commands enclosed within
	     braces.

Example:     Count paragraphs in each chapter

             $i=0;
             foreach //chapter {

lib/XML/XSH2/Help.pm  view on Meta::CPAN

	     any type, quotes, double-quotes, '$' character nor '@'
	     character, it is treated as a literal token which evaluates to
	     itself.

END


$HELP{'nodename'}=[<<'END'];
Node-name argument type

description:
	     An [expression] which evaluates to a valid name of an element,
	     attribute or processing-instruction node. As long as the
	     expression contains no whitespace, no brackets of any type,
	     quotes, double-quotes, '$' character, nor '@' character, it is
	     treated as a literal token which evaluates to itself.

END


$HELP{'xpath'}=[<<'END'];
XPath argument type

description:
	     XSH2 can evaluate XPath expressions as defined in W3C
	     recommendation at http://www.w3.org/TR/xpath with only a
	     little limitation on use of syntactically ignorable
	     whitespace. (Nice interactive XPath tutorials and references
	     can be found at http://www.zvon.org.)

	     In order to allow XSH2 to use white-space as a command
	     argument delimiter (which is far more convenient to type than,
	     say, commas), the use of white-space in XPath is slightly
	     restricted. Thus, in XSH2, white-space can only occur in those
	     parts of an XPath expression, that are surrounded by either
	     brackets, square brackets, single or double quotes. So, for
	     example, otherwise valid XPath expression like

             / foo / bar [ @baz = "bar" ]
	     should in XSH2 be written as either of

             /foo/bar[ @baz = "bar" ]
	     avoiding any white-space outside the square brackets, or
	     completely enclosed in brackets as in

             ( / foo / bar [ @baz = "bar" ] ).
	     XSH2 provides a number of powerful XPath extension functions,
	     listed below and described in separate sections. XPath
	     extension functions by default belong to XSH2 namespace
	     'http://xsh.sourceforge.net/xsh/' with a namespace prefix set
	     to 'xsh'. A program may however call the [xpath-extensions]
	     command to map XSH2 XPath extension functions into the default
	     namespace, so that they may be used directly without any
	     prefix.

	     XPath extension functions defined in XSH2: xsh:base-uri,
	     xsh:context, xsh:current, xsh:doc, xsh:document,
	     xsh:document-uri, xsh:documents, xsh:evaluate, xsh:filename,
	     xsh:grep, xsh:id2, xsh:if, xsh:join, xsh:lc, xsh:lcfirst,
	     xsh:lineno, xsh:lookup, xsh:map, xsh:match, xsh:matches,
	     xsh:max, xsh:min, xsh:new-attribute, xsh:new-cdata,
	     xsh:new-chunk, xsh:new-comment, xsh:new-element,
	     xsh:new-element-ns, xsh:new-pi, xsh:new-text, xsh:parse,
	     xsh:path, xsh:resolve-uri, xsh:reverse, xsh:same,
	     xsh:serialize, xsh:span, xsh:split, xsh:sprintf, xsh:strmax,
	     xsh:strmin, xsh:subst, xsh:substr, xsh:sum, xsh:times, xsh:uc,
	     xsh:ucfirst, xsh:var

Example:     Open a document and count all sections containing a subsection

             xsh $scratch/> $v := open mydocument1.xml;
             xsh $v/> $k := open mydocument2.xml;
             xsh $k/> count //section[subsection]; # searches k
             xsh $k/> count $v//section[subsection]; # searches v

END


$HELP{'expression'}=[<<'END'];
expression

description:
	     An XSH2 expression can be one of the following constructs:

	       1. XPath 1.0 expression with the following restriction:
	       whitespace is only allowed within parts the expression
	       enclosed in quotes (literal strings) or brackets (XPath has
	       two types of brackets - plain and square). Thus, while '/
	       foo / bar' is a valid XPath expression matching element
	       named bar under root element foo, in XSH2 this expression
	       must be written as '/foo/bar' or '(/ foo / bar)' or
	       '(/foo/bar)' etc. The reason for this restriction is simple:
	       XSH2, like most shell languages, uses whitespace as argument
	       delimiter so it must be able to determine expression
	       boundaries (otherwise, '/ bar / foo' could be anything
	       between one and four expressions).

	       2. In certain contexts, usually when a filename or a node
	       name is expected as an argument, bareword (otherwise XPath)
	       expressions are evaluated in a non-standard way: as long as
	       the expression contains no whitespace, no brackets of any
	       kind, quotes, double-quotes, '$' character, nor '@'
	       character, it is treated as a literal token which evaluates
	       to itself. This usually happens if a file name or element
	       name is expected, but some other commands, like [print],
	       evaluate its arguments in this way. In order to force an
	       XPath evaluation in such situations, the entire expression
	       should be enclosed with brackets '(...)'. For example, with
	       [open] command, 'open file' or 'open "file"' both open a
	       file whose name is 'file' (literally) whereas 'open (file)'
	       or 'open @file' compute the file name by evaluating '(file)'
	       or '@file' respectively, as XPath expressions.

	       3. Perl blocks. These are enclosed in braces like: '{
	       perl-code }'. Perl expressions can be used to evaluate more
	       complicated things, like complex string expressions, regexp
	       matches, perl commands, etc. In short, arbitrary perl. Of
	       course, things like '{`ls`}' work too, and that's why we
	       don't need to define shell-like backticks in XSH2 itself.

	       4. Result of one XSH2 command can be directly passed as an

lib/XML/XSH2/Help.pm  view on Meta::CPAN

	     works on spans of nodes. It wraps spans (i.e. sequence of
	     adjacent nodes between (and including) a start node and an end
	     node) with a new element whose name is specified as the first
	     argument. Nodes within each span must have the same parent
	     node. The spans to be wrapped are defined by a pair of
	     node-lists in the second and third argument. The first
	     node-list specifies the start node of one or more spans, while
	     the second node-list should contain the corresponding end
	     nodes. The two node-lists must evaluate to the exactly same
	     number of nodes, otherwise a runtime error is reported. The
	     N'th span is then defined as a span starting on the N'th node
	     in the start node-list and ending at the N'th node in the end
	     node-list.

	     All nodes within the spans are removed from the document and
	     placed into the newly generated elements. The wrapping
	     elements are put back into the document tree at the positions
	     previously occupied by the node-spans.

	     The command returns a node-list containing the newly created
	     wrapping elements.

Example:
             xsh $scratch/> $foo := create { "<root>\n<a/><b/>\n<a/><b/>\n<a/><b/>\n</root>" };
             xsh $foo/> wrap-span 'span' //a //b;
             xsh $foo/> ls /;
             <?xml version="1.0" encoding="utf-8"?>
             <root>
             <span><a/><b/></span>
             <span><a/><b/></span>
             <span><a/><b/></span>
             </root>

see also:     xinsert insert move xmove

END

$HELP{'wrap_span'}=$HELP{'wrap-span'};

$HELP{'xinsert'}=[<<'END'];
usage:       xinsert [--namespace [expression]] [node-type] [expression] [location] [xpath]
             
aliases:     xadd

description:
	     Create new nodes of the [node-type] given in the 1st argument
	     of name specified in the 2nd argument and insert them to
	     [location]s relative to nodes in the node-list specified in
	     the 4th argument.

	     For element nodes, the the 2nd argument [expression] should
	     evaluate to something like "<element-name att-name='attvalue'
	     ...>". The '<' and '>' characters are optional. If no
	     attributes are used, the expression may simply consist the
	     element name. Note, that in the first case, the quotes are
	     required since the expression contains spaces.

	     Attribute nodes use the following syntax: "att-name='attvalue'
	     [...]".

	     For the other types of nodes (text, cdata, comments) the
	     expression should contain the node's literal content. Again,
	     it is necessary to quote all whitespace and special characters
	     as in any expression argument.

	     The [location] argument should be one of: 'after', 'before',
	     'into', 'replace', 'append' or 'prepend'. See documentation of
	     the [location] argument type for more detail.

	     Optionally, for element and attribute nodes, a namespace may
	     be specified with '--namespace' or ':n'. If used, the
	     expression should evaluate to the desired namespace URI and
	     the name of the element or attribute being inserted must have
	     a prefix.

	     The command returns a node-list consisting of nodes it
	     created.

	     Note, that instead of 'xinsert', you can alternatively use one
	     of [xsh:new-attribute], [xsh:new-cdata], [xsh:new-chunk],
	     [xsh:new-comment], [xsh:new-element], [xsh:new-element-ns],
	     [xsh:new-pi], and [xsh:new-text] together with the command
	     [xcopy].

Example:     Give each chapter a provisional title element.

             xsh> my $new_titles := xinsert element "<title font-size=large underline=yes>" \
                              into /book/chapter
             xsh> xinsert text "Change me!" into $new_titles;

Example:     Same as above, using xcopy and xsh:new-... instead of xinsert

             xsh> my $new_titles := xcopy xsh:new-element("title","font-size","large","underline","yes") \
                              into /book/chapter
             xsh> xcopy xsh:new-text("Change me!") into $new_titles;

see also:     insert move xmove

END

$HELP{'xadd'}=$HELP{'xinsert'};

$HELP{'node-type'}=[<<'END'];
Node-type argument type

description:
	     One of: element, attribute, text, cdata, comment, chunk and
	     (EXPERIMENTALLY!) entity_reference. A chunk is a character
	     string which forms a well-balanced piece of XML.

Example:
             add element hobbit into //middle-earth/creatures;
             add attribute 'name="Bilbo"' into //middle-earth/creatures/hobbit[last()];
             add chunk '<hobbit name="Frodo">A small guy from <place>Shire</place>.</hobbit>' 
               into //middle-earth/creatures;

END


$HELP{'location'}=[<<'END'];
Location argument type

description:
	     One of: 'after', 'before', 'into', 'append', 'prepend',
	     'replace'.

	     This argument is required by all commands that insert nodes to
	     a document in some way to a destination described by an XPath
	     expression. The meaning of the values listed above is supposed
	     be obvious in most cases, however the exact semantics for
	     location argument values depends on types of both the source
	     node and the target node.

	     'after/before' place the node right after/before the
	     destination node, except for when the destination node is a
	     document node or one of the source nodes is an attribute: If
	     the destination node is a document node, the source node is
	     attached to the end/beginning of the document (remember: there
	     is no "after/before a document"). If both the source and
	     destination nodes are attributes, then the source node is
	     simply attached to the element containing the destination node
	     (remember: there is no order on attribute nodes). If the
	     destination node is an attribute but the source node is of a
	     different type, then the textual content of the source node is
	     appended to the value of the destination attribute (i.e. in
	     this case after/before act just as append/prepend).

	     'append/prepend' appends/prepends the source node to the
	     destination node. If the destination node can contain other
	     nodes (i.e. it is an element or a document node) then the
	     entire source node is attached to it. In case of other
	     destination node types, the textual content of the source node
	     is appended/prepended to the content of the destination node.

	     'into' can also be used to place the source node to the end of
	     an element (in the same way as 'append'), to attach an
	     attribute to an element, or, if the destination node is a text
	     node, cdata section, processing-instruction, attribute or
	     comment, to replace its textual content with the textual
	     content of the source node.

	     'replace' replaces the entire destination node with the source
	     node except for the case when the destination node is an
	     attribute and the source node is not. In such a case only the
	     value of the destination attribute is replaced with the
	     textual content of the source node. Note also that document
	     node can never be replaced.

END


$HELP{'move'}=[<<'END'];
usage:       move [xpath] [location] [xpath]
             
aliases:     mv

description:
	     'move' command acts exactly like [copy], except that it
	     removes the source nodes after a successful copy. Remember
	     that the moved nodes are actually different nodes from the
	     original ones (which may not be obvious when moving nodes
	     within a single document into locations that do not require
	     type conversion). So, after the move, the original nodes don't
	     belong to any document and are automatically destroyed unless
	     some variable still contains to them.

	     This command returns a node-list consisting of nodes it
	     created on the target locations.

	     See [copy] for more details on how the copies of the moved
	     nodes are created.

see also:     xmove copy xcopy insert xinsert

END

$HELP{'mv'}=$HELP{'move'};

$HELP{'xmove'}=[<<'END'];
usage:       xmove [--respective|:r] [--preserve-order|:p] [xpath] [location] [xpath]
             
aliases:     xmv

description:
	     Like [xcopy], except that 'xmove' removes the source nodes
	     after a successful copy. Remember that the moved nodes are
	     actually different nodes from the original ones (which may not
	     be obvious when moving nodes within a single document into
	     locations that do not require type conversion). So, after the
	     move, the original nodes don't belong to any document and are
	     automatically destroyed unless still contained in some
	     variable.

	     This command returns a node-list consisting of all nodes it
	     created on the target locations.

	     If '--respective|:r' option is used, then the target node-list
	     [expression] is evaluated in the context of the source node

lib/XML/XSH2/Help.pm  view on Meta::CPAN

	     with given names and respective values.

END


$HELP{'xsh:new-element'}=[<<'END'];
usage:       node-set xsh:new-element(string NAME,[string ATTR1-NAME1,
  string ATTR-VALUE1, ...])
             
description:
	     Create a new element node with given 'NAME' and optionally
	     attributes with given names and values and return a node-set
	     containing the new node as its only member.

END


$HELP{'xsh:new-element-ns'}=[<<'END'];
usage:       node-set xsh:new-element-ns(string NAME,string NS,[string ATTR1-NAME1,
  string ATTR-VALUE1, ...])
             
description:
	     Create a new element node with given 'NAME' and namespace-uri
	     'NS' and optionally attributes with given names and values and
	     return a node-set containing the new node as its only member.

END


$HELP{'xsh:new-text'}=[<<'END'];
usage:       node-set xsh:new-text(string DATA)
             
description:
	     Create a new text node containing given 'DATA' and return a
	     node-set containing the new node as its only member.

END


$HELP{'xsh:new-comment'}=[<<'END'];
usage:       node-set xsh:new-comment(string DATA)
             
description:
	     Create a new comment node containing given 'DATA' and return a
	     node-set containing the new node as its only member.

END


$HELP{'xsh:new-pi'}=[<<'END'];
usage:       node-set xsh:new-pi(string NAME, [string DATA])
             
description:
	     Create a new processing instruction node node with given
	     'NAME' and (optionally) given 'DATA' and return a node-set
	     containing the new node as its only member.

END


$HELP{'xsh:new-cdata'}=[<<'END'];
usage:       node-set xsh:new-cdata(string DATA)
             
description:
	     Create a new cdata section node node filled with given 'DATA'
	     and return a node-set containing the new node as its only
	     member.

END


$HELP{'xsh:new-chunk'}=[<<'END'];
usage:       node-set xsh:new-chunk(string XML)
             
description:
	     This is just an alias for [xsh:parse]. It parses given piece
	     of XML and returns a node-set consisting of the top-level
	     element within the parsed tree.

END


$HELP{'xsh:map'}=[<<'END'];
usage:       node-set xsh:map(node-set NODE, string XPATH)
             
description:
	     This function is very similar to EXSLT 'dynamic:map' function.
	     The description below is almost literally taken from the EXSLT
	     specification.

	     The 'xsh:map' function evaluates the expression passed as the
	     second argument for each of the nodes passed as the first
	     argument, and returns a node-set of those values.

	     The expressions are evaluated relative to the nodes passed as
	     the first argument. In other words, the value for each node is
	     calculated by evaluating the XPath expression with all context
	     information being the same as that for the call to the
	     'xsh:map' function itself, except for the following:

	     1) the context node is the node whose value is being
	     calculated, 2) the context position is the position of the
	     node within the node set passed as the first argument to the
	     'xsh:map' function, arranged in document order, and 3) the
	     context size is the number of nodes passed as the first
	     argument to the dyn:map function.

	     If the expression string passed as the second argument is an
	     invalid XPath expression (including an empty string), this
	     function returns an empty node set.

	     If 'XPATH' evaluates as a node set, the 'xsh:map' function
	     returns the union of the node sets returned by evaluating the
	     expression for each of the nodes in the first argument. Note
	     that this may mean that the node set resulting from the call
	     to the 'xsh:map' function contains a different number of nodes
	     from the number in the node set passed as the first argument
	     to the function.

	     If 'XPATH' evaluates as a number, the 'xsh:map' function
	     returns a node set containing one 'xsh:number' element
	     (namespace 'http://xsh.sourceforge.net/xsh/') for each node in
	     the node set passed as the first argument to the dyn:map
	     function, in document order. The string value of each
	     'xsh:number' element is the same as the result of converting

lib/XML/XSH2/Help.pm  view on Meta::CPAN


  Along with XPath, Perl is one of two XSH2 expression languages, and
  borrows XSH2 its great expressive power. Perl is a language optimized for
  scanning arbitrary text files, extracting information from those text
  files, and printing reports based on that information. It has built-in
  regular expressions and powerful yet easy to learn data structures
  (scalars, arrays, hash tables). It's also a good language for many system
  management tasks. XSH2 itself is written in Perl (except for the XML
  engine, which uses libxml2 library written in C by Daniel Veillard).

  Calling Perl
  ------------

    Perl [expressions or blocks of code] can either be used as arguments to
    any XSH2 command. One of them is [perl] command which simply evaluates
    the given Perl block. Other commands, such as [map], even require Perl
    expression argument and allow quickly change DOM node content. Perl
    expressions may also provide lists of strings to iterate over with a
    [foreach] loop, or serve as conditions for [if], [unless], and [while]
    statements.

    To prevent conflict between XSH2 internals and the evaluated Perl code,
    XSH2 runs such code in the context of a special namespace
    'XML::XSH2::Map'. As described in the section [Variables], XSH2 string
    variables may be accessed and possibly assigned from Perl code in the
    most obvious way, since they actually are Perl variables defined in the
    'XML::XSH2::Map' namespace.

    The interaction between XSH2 and Perl actually works the other way
    round as well, so that you may call back XSH2 from the evaluated Perl
    code. For this, Perl function 'xsh' is defined in the 'XML::XSH2::Map'
    namespace. All parameters passed to this function are interpreted as
    XSH2 commands.

    Moreover, the following Perl helper functions are defined:

    'xsh(string,....)' - evaluates given string(s) as XSH2 commands.

    'call(name)' - call a given XSH2 subroutine.

    'count(string)' - evaluates given string as an XPath expression and
    returns either literal value of the result (in case of boolean, string
    and float result type) or number of nodes in a returned node-set.

    'literal(string|object)' - if passed a string, evaluates it as a XSH2
    expression and returns the literal value of the result; if passed an
    object, returns literal value of the object. For example,
    'literal('$doc/expression')' returns the same value as
    'count('string($doc/expression)')'.

    'serialize(string|object)' - if passed a string, it first evaluates the
    string as a XSH2 expression to obtain a node-list object. Then it
    serializes the object into XML. The resulting string is equal to the
    output of the XSH2 command [ls] applied on the same expression or
    object expression only without indentation and folding.

    'type(string|object)' - if passed a string, it first evaluates the
    string as XSH2 expression to obtain a node-list object. It returns a
    list of strings representing the types of nodes in the node-list
    (ordered in the canonical document order). The returned type strings
    are: 'element', 'attribute', 'text', 'cdata', 'pi', 'entity_reference',
    'document', 'chunk', 'comment', 'namespace', 'unknown'.

    'nodelist(string|object,...)' - converts its arguments to objects if
    necessary and returns a node-list consisting of the objects.

    'xpath(string, node?)' - evaluates a given string as an XPath
    expression in the context of a given node and returns the result.

    'echo(string,...)' - prints given strings on XSH2 output. Note, that in
    the interactive mode, XSH2 redirects all output to a specific terminal
    file handle stored in the variable '$OUT'. So, if you for example mean
    to pipe the result to a shell command, you should avoid using STDOUT
    filehandle directly. You may either use the usual 'print' without a
    filehandle, use the 'echo' function, or use '$OUT' as a filehandle.

    In the following examples we use Perl to populate the Middle-Earth with
    Hobbits whose names are read from a text file called 'hobbits.txt',
    unless there are some Hobbits in Middle-Earth already.

Example: Use Perl to read text files

    unless (//creature[@race='hobbit']) {
      perl {
        open my $fh, "hobbits.txt" };
        @hobbits=<$file>;
        close $fh;
      }
      foreach { @hobbits } {
        copy xsh:new-element("creature","name",.,"race","hobbit")
          into m:/middle-earth/creatures;
      }
    }

Example: The same code as a single Perl block

    perl {
      unless (count(//creature[@race='hobbit'])) {
        open my $file, "hobbits.txt";
        foreach (<$file>) {
          xsh(qq{insert element "<creature name='$_' race='hobbit'>"
            into m:/middle-earth/creatures});
        }
        close $file;
      }
    };

  Writing your own XPath extension functions in Perl
  --------------------------------------------------

    XSH2 allows users to extend the set of XPath functions by providing
    extension functions written in Perl. This can be achieved using the
    [register-function] command. The perl code implementing an extension
    function works as a usual perl routine accepting its arguments in '@_'
    and returning the result. The following conventions are used:

    The arguments passed to the perl implementation by the XPath engine are
    simple scalars for string, boolean and float argument types and
    'XML::LibXML::NodeList' objects for node-set argument types. The
    implementation is responsible for checking the argument number and
    types. The implementation may use general Perl functions as well as

lib/XML/XSH2/Help.pm  view on Meta::CPAN

$HELP{'commands'}=$HELP{'command'};
$Apropos = {
             'xsh:lc' => undef,
             'quiet' => 'turn off many XSH2 messages',
             'canonical' => 'serialize nodes as to canonical XML',
             'xsh:matches' => undef,
             'create' => 'make a new document from a given XML fragment',
             'xpath-extensions' => 'map predefined XSH2 XPath extension functions to no or other namespace',
             'documents' => 'display a list of open documents',
             'xsh:times' => undef,
             'location' => 'relative destination specification (such as after, before, etc.)',
             'xsh:span' => undef,
             'nodebug' => 'turn off debugging messages',
             'map' => 'transform node value/data using Perl or XPath expression',
             'xpath' => 'XPath expression',
             'parser-completes-attributes' => 'turn on/off parser\'s ability to fill default attribute values',
             'remove' => 'remove given nodes',
             'variables' => 'list global variables',
             'validate' => 'validate a document against a DTD, RelaxNG, or XSD schemas',
             'xsh:ucfirst' => undef,
             'xsh:same' => undef,
             'ifinclude' => 'conditionally include another XSH2 source in current position',
             'change-ns-prefix' => 'change namespace prefix (EXPERIMENTAL)',
             'run-mode' => 'switch into normal execution mode (quit [test-mode])',
             'xsh:subst' => undef,
             'query-encoding' => 'declare the charset of XSH2 source files and terminal input',
             'locate' => 'show a given node location (as a canonical XPath)',
             'index' => 'index a static document for faster XPath lookup',
             'edit' => 'Edit parts of a XML document in a text editor.',
             'xsh:new-comment' => undef,
             'edit-string' => 'Edit a string or variable in a text editor.',
             'wrap-span' => 'wrap spans of nodes into elements',
             'ls' => 'list a given part of a document as XML',
             'iterate' => 'iterate a block over current subtree',
             'parser-expands-xinclude' => 'turn on/off transparent XInclude insertion by parser',
             'nodename' => 'specifying names of DOM nodes',
             'exec' => 'execute a shell command',
             'open' => 'load an XML, HTML, or Docbook SGML document from a file, pipe or URI',
             'empty-tags' => 'turn on/off serialization of empty tags',
             'namespaces' => 'List namespaces available in a context of a given nodes',
             'register-function' => 'define XPath extension function (EXPERIMENTAL)',
             'skip-dtd' => 'turn on/off serialization of DTD DOCTYPE declaration',
             'xpath-axis-completion' => 'sets TAB completion for axes in xpath expressions in the interactive mode',
             'unless' => 'negated if statement',
             'set-dtd' => 'set document\'s DTD declaration',
             'rename' => 'quickly rename nodes with in-line Perl code',
             'xsh:doc' => undef,
             'backups' => 'turn on backup file creation',
             'doc-info' => 'displays various information about a document',
             'node-type' => 'node type specification (such as element, attribute, etc.)',
             'xsh:map' => undef,
             'xsh:new-element-ns' => undef,
             'xsh:sum' => undef,
             'process-xinclude' => 'load and insert XInclude sections',
             'do' => 'execute a given block of commands',
             'xinsert' => 'create nodes on all target locations',
             'xsh:documents' => undef,
             'register-xsh-namespace' => 'register a prefix for the XSH2 namespace',
             'apropos' => 'search the documentation',
             'verbose' => 'make XSH2 print many messages',
             'xsh:new-cdata' => undef,
             'xsh:parse' => undef,
             'filename' => 'specifying filenames',
             'unregister-namespace' => 'unregister namespace prefix',
             'throw' => 'throw an exception',
             'xsh:new-text' => undef,
             'nobackups' => 'turn off backup file creation',
             'parser-expands-entities' => 'turn on/off parser\'s tendency to expand entities',
             'set-enc' => 'set document\'s charset (encoding)',
             'while' => 'simple while loop',
             'try' => 'try/catch statement',
             'clone' => 'clone a given document',
             'save' => 'save a document as XML or HTML',
             'version' => 'show version information',
             'xsh:split' => undef,
             'xsh:evaluate' => undef,
             'perl' => 'evaluate in-line Perl code',
             'xsh:match' => undef,
             'cd' => 'change current context node',
             'redo' => 'restart the innermost enclosing loop block',
             'defs' => 'list all user-defined subroutines',
             'xsh:filename' => undef,
             'perl-code' => 'in-line code in Perl programming language',
             'foreach' => 'loop iterating over a node-list or a perl array',
             'xsh:strmax' => undef,
             'xsh:reverse' => undef,
             'print' => 'print stuff on standard or standard error output',
             'type' => undef,
             'xsh:sprintf' => undef,
             'lcd' => 'change system working directory',
             'xsh:new-attribute' => undef,
             'document' => 'specifying documents',
             'subroutine' => 'name of a sub-routine',
             'unfold' => 'unfold elements folded with fold command',
             'eval' => 'evaluate given expression as XSH commands',
             'xpath-completion' => 'turn on/off TAB completion for xpath expressions in the interactive mode',
             'xsh:document-uri' => undef,
             'assign' => 'variable assignment',
             'call' => 'indirect call to a user-defined routine (macro)',
             'help' => 'on-line documentation',
             'my' => 'Create a new lexically scoped variable',
             'strip-whitespace' => 'strip leading and trailing whitespace',
             'set_filename' => 'change filename or URL associated with a document',
             'stream' => 'process selected elements from an XML stream (EXPERIMENTAL)',
             'block' => 'a block of XSH2 commands',
             'register-xhtml-namespace' => 'register a prefix for the XHTML namespace',
             'xsh:current' => undef,
             'last' => 'immediately exit an enclosing loop',
             'xsh:new-chunk' => undef,
             'xsh:base-uri' => undef,
             'pwd' => 'show current context node location (as a canonical XPath)',
             'move' => 'move nodes (in the one-to-one mode)',
             'xsh:new-element' => undef,
             'pedantic-parser' => 'make the parser more pedantic',
             'xsh:uc' => undef,
             'xsh:lookup' => undef,
             'settings' => 'list current settings using XSH2 syntax',
             'xmove' => 'move nodes (in the all-to-every mode)',
             'insert' => 'create a node in on a given target location',
             'expression' => 'expression argument type',
             'declare-ns' => 'create a special attribute declaring an XML namespace (EXPERIMENTAL)',



( run in 0.937 second using v1.01-cache-2.11-cpan-39bf76dae61 )