Skip to content

Instantly share code, notes, and snippets.

@mdom

mdom/dom_to_sax.pl

Created Sep 18, 2019
Embed
What would you like to do?
dom_to_sax
sub new_nodes {
my @events;
for my $node (@_) {
my $type = $node->type;
if ( $type eq 'text' ) {
push @events, [ 'start_text', $node ];
}
elsif ( $type eq 'tag' ) {
my $tag = $node->tag;
push @events, [ "start_$tag", $node ];
if ( my @childs = @{ $node->child_nodes } ) {
push @events, new_nodes(@childs);
}
push @events, [ "stop_$tag", $node ];
}
}
return @events;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment