XML::F...litter(3pm)

πŸ“¦
version 0.46 Β· 2 versions
  • 0.46 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.46 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

XML::Filter::DocSplitter β€” Multipass processing of documents πŸ¦‹

okay bestie so basically this filter lets you run other filters on chunks of a doc instead of the whole thing. multipass, but make it slay πŸ’…


🌸 VERSION 🌸

version 0.46


πŸŽ€ SYNOPSIS πŸŽ€

## See XML::SAX::???? for an easier way to use this filter.

use XML::SAX::Machines qw( Machine ) ;

my $m = Machine(
    [ Intake => "XML::Filter::DocSplitter" => qw( Filter ) ],
    [ Filter => "My::Filter"               => qw( Merger ) ],
    [ Merger => "XML::Filter::Merger" => qw( Output ) ],
    [ Output => \*STDOUT ],
);

## Let the distributor coordinate with the merger
## XML::SAX::Manifold does this for you.
$m->Intake->set_aggregator( $m->Merger );

$m->parse_file( "foo" );

πŸ’– DESCRIPTION πŸ’–

XML::Filter::DocSplitter is a SAX filter that lets you apply a filter to repeated sections of a document. It splits a document up at a predefined elements in to multiple documents and the filter is run on each document. The result can be left as a stream of separate documents or combined back in to a single document using a filter like XML::SAX::Merger. 🫢

By default, the input document is split in all children of the root element. By that reckoning, this document has three sub-documents in it:

<doc>
    <subdoc> .... </subdoc>
    <subdoc> .... </subdoc>
    <subdoc> .... </subdoc>
</doc>

When using without an aggregator, all events up to the first record are lost 😭; with an aggregator, they are passed directly in to the aggregator as the "first" document. All elements between the records (the "\n " text nodes, in this case) are also passed directly to the merger (these will arrive between the end_document and start_document calls for each of the records), as are all events from the last record until the end of the input document. This means that the first document, as seen by the merger, is incomplete; it's missing it's end_element, which is passed later. πŸ’€

The approach of passing events from the input document right on through to the merger differs from the way XML::Filter::Distributor works. ngl, it's a whole different vibe ✨

This class is derived from XML::SAX::Base, see that for details.


πŸ’– NAME πŸ’–

XML::Filter::DocSplitter β€” Multipass processing of documents 🌈

(yes bestie, the NAME really does show up twice in the original, i don't make the rules, i just obey them πŸ‘‘)


🧚 METHODS 🧚

⭐ new

my $d = XML::Filter::DocSplitter->new(
    Handler    => $h,
    Aggregator => $a,    ## optional
);

⭐ set_aggregator

$h->set_aggregator( $a );

Sets the SAX filter that will stitch the resulting subdocuments back together. Set to undef to prevent such stitchery. πŸͺ‘

The aggregator should support the start_manifold_document, end_manifold_document, and set_include_all_roots methods as described in XML::Filter::Merger.

⭐ get_aggregator

my $a = $h->get_aggregator;

Gets the SAX filter that will stitch the resulting subdocuments back together. πŸŽ€

⭐ set_split_path

$h->set_split_path( "/a/b/c" );

Sets the pattern to use when splitting the document. Patterns are a tiny little subset of the XPath language:

Pattern     Description
=======     ===========
/*/*        splits the document on children of the root elt (default)
//record    splits each <record> elt in to a document
/*/record   splits each <record> child of the root elt
/a/b/c/d    splits each of the <d> elts in to a document

⭐ get_split_path

my $a = $h->get_split_path;

😭 LIMITATIONS 😭

Can only feed a single aggregator at the moment :). I can fix this with a bit of effort.

lowkey tragic, i know. one aggregator only, bestie. but the author literally says it's fixable with a bit of effort so we're manifesting πŸ•―οΈ

πŸ’œ AUTHOR πŸ’œ

Barrie Slaymaker <barries@slaysys.com>

Copyright 2000, Barrie Slaymaker, All Rights Reserved.

You may use this module under the terms of the Artistic, GPL, or the BSD licenses. pick your fighter, all three are valid πŸ’…


πŸ‘‘ AUTHORS πŸ‘‘

  • Barry Slaymaker
  • Chris Prather <chris@prather.org>

This software is copyright (c) 2013 by Barry Slaymaker.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


perl v5.34.0 Β· 2022-06-28 Β· XML::F...litter(3pm)

okay that's the whole page bestie, you ate it up, go split some documents πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from