XML-Overlay

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

--- #YAML:1.0
name: XML-Overlay
version: 0.01
author:
  - Matt S Trout <mstrout@cpan.org>
abstract: Apply overlays to XML documents
license: perl
requires:
  Class::XML: 0.04
  Test::More: 0.0
provides:
  XML::Overlay:
    file: lib/XML/Overlay.pm
    version: 0.01
  XML::Overlay::action:
    file: lib/XML/Overlay/action.pm

lib/XML/Overlay.pm  view on Meta::CPAN

  foreach ($self->target) {
    push(@changes, $_->action_closure($context));
  }
  foreach (@changes) {
    $_->();
  }
}

=head1 NAME

XML::Overlay - Apply overlays to XML documents

=head1 SYNOPSIS

  # Original XML document:
  <blub>
    <foo meh="3" />
    <bar>
      <spam bleem="3" />
    </bar>
  </blub>

lib/XML/Overlay.pm  view on Meta::CPAN

    </target>
    <target xpath="//spam">
      <action type="insertAfter">
        <meh1 />
        <meh2 />
      </action>
      <action type="delete" />
    </target>
  </Overlay>

  my $o_tree = XML::Overlay->new(xml => $o_source); # Load overlay doc

  my $d_tree = Class::XML->new(xml => $d_source); # Load initial doc

  $o_tree->process($d_tree);

  print "${d_tree}"; # Class::XML used above for overloaded stringify

  # Outputs:
  <blub>
    

lib/XML/Overlay.pm  view on Meta::CPAN

        <meh1 />
        <meh2 />
      
    </bar>
  </blub>

=head1 DESCRIPTION

XML::Overlay is a simple collection of Class::XML modules that provide a
mechanism somewhat inspired by Mozilla's XUL Overlays, but designed for
manipulating general XML documents. The overlay document contains one or more
B<target> elements, each with an B<xpath> attribute which specifies what nodes
of the source document should be captured and transformed; each B<target>
element contains one or more B<action> elements which specifies the action(s)
to perform on each XPath node captured by the parent.

Note that the XPath tree is modified in-place, so ensure you process a copy if
you want your original document intact afterwards as well!

=head1 DETAILS



( run in 0.945 second using v1.01-cache-2.11-cpan-3b35f9de6a3 )