The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XML::Axk::Core::L1 - awk-like XML processor, language 1

EXAMPLE

    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};

PATTERNS AND ACTIONS

  • 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>:

    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 {<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.

  • 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:

        on { xpath(q<//item>) } run {say "$NOW: " . $E->getTagName}, CIAO
        perform {say "$NOW: " . $E->getTagName} xpath(q<//item>), CIAO

VARIABLES

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.

At present, L1 uses XML::DOM.

$D

The current XML document (XML::DOM::Document)

$E

The XML element that was matched (XML::DOM::Element)

$NOW

The current phase, as a human-readable string: entering for HI, leaving for BYE, and both for CIAO.

MATCHERS

  • 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.

  • sel('selector')

    Match nodes that match the given selector.

  • always, never

    Always or never match, respectively.

SPECIAL ACTIONS

  • pre_all {<block>}

    Run <block> before any file is processed.

  • pre_file {<block>}

    Run <block>($filename) before each file is processed.

  • post_file {<block>}

    Run <block>($filename) after each file is processed.

  • post_all {<block>}

    Run <block> after all files have been processed.

AUTHOR

Christopher White, cxwembedded at gmail.com

CONTACT

For any bug reports, feature requests, or questions, please see the information in XML::Axk.

LICENSE AND COPYRIGHT

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.