XML::Axk::Core::L1 - awk-like XML processor, language 1
L1 on { xpath(q<//item>) } run {say "$NOW: " . $E->getTagName}, CIAO # "CIAO" can also be "HI" or "BYE" (default BYE). # "leaving" is a synonym for "on" with no HI/BYE/CIAO. whenever { xpath(q<//item>) } run {say "$NOW: " . $E->getTagName}; # the same as the "on ... CIAO" line entering { xpath(q<//item>) } run {say "$NOW: " . $E->getTagName};
on {<matcher>} run {<action>} [, <when>]
Whenever <matcher> says that a node matches, run <action>. The optional <when> parameter says when in the course of processing to run <action>:
<matcher>
<action>
<when>
HI
When the node is first reached, before any of its children are processed
BYE
After all of the node's children have been processed. This is the default so that you have the text content of the node available for inspection.
CIAO
Both HI and BYE. Suggestions for alternative terminology are welcome.
entering, whenever leaving
entering
whenever
leaving
entering {<matcher>} run {<action>} whenever {<matcher>} run {<action>} leaving {<matcher>} run {<action>}
The same as on {} run {}, with when set to HI, CIAO, or BYE respectively.
on {} run {}
when
perform { <action> } <matcher> [, <when>]
If you prefer RPN, or you want to save some characters, you can put the <matcher> after the <action> using perform. For example, the following two lines have exactly the same effect:
perform
on { xpath(q<//item>) } run {say "$NOW: " . $E->getTagName}, CIAO perform {say "$NOW: " . $E->getTagName} xpath(q<//item>), CIAO
When an <action> is running, it has access to predefined variables that hold the state of the element being matched. This is similar to $0, $1, ... in awk.
$0
$1
At present, L1 uses XML::DOM.
The current XML document (XML::DOM::Document)
The XML element that was matched (XML::DOM::Element)
The current phase, as a human-readable string: entering for HI, leaving for BYE, and both for CIAO.
both
xpath('xpath expression')
Match nodes that match the given XPath expression. Remember that Perl will interpolate @name in double-quotes, so single-quote or q{} your XPath expressions.
@name
q{}
sel('selector')
Match nodes that match the given selector.
always, never
always
never
Always or never match, respectively.
pre_all {<block>}
Run <block> before any file is processed.
<block>
pre_file {<block>}
Run <block>($filename) before each file is processed.
<block>($filename)
post_file {<block>}
Run <block>($filename) after each file is processed.
post_all {<block>}
Run <block> after all files have been processed.
Christopher White, cxwembedded at gmail.com
cxwembedded at gmail.com
For any bug reports, feature requests, or questions, please see the information in XML::Axk.
Copyright (c) 2018 Christopher White. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). Details are in the LICENSE file accompanying this distribution.
To install Object::TinyDefaults, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Object::TinyDefaults
CPAN shell
perl -MCPAN -e shell install Object::TinyDefaults
For more information on module installation, please visit the detailed CPAN module installation guide.