package Enode; sub new { my $pkg = shift; my $text = shift; #reference to a text my $self = {}; bless $self,$pkg; if ($$text =~ s/^<([^>]+)>//) #finds new xml tag { my $key = $1; $self->{$key} = []; unless ($key =~ s/\/\s*$//) #is no autoclosing tag { while ($$text !~ s/<\/[^>]*>) #anti tag not found { push(@{$self->{$key}},(s/^([^>]+)//?new Tnode($1):new Enode($text)); #if text is found: textnode is pushed on list, else must be a new xml tag so: elementnode is pushed on list } } return($self); } } sub topdown { my $self = shift; my $functionref = shift; my $key = keys %$self; &$functionref($self,@_); foreach my $node (@{$self->{$key}}) { $node->topdown($functionref,@_); } } sub bottomup { my $self = shift; my $functionref = shift; my $key = keys %$self; foreach my $node (@{$self->{$key}}) { $node->topdown($functionref,@_); } &$functionref($self,@_); } sub strange { my $self = shift; my $functionref = shift; my $key = keys %$self; foreach my $node (@{$self->{$key}}) { &$functionref($node,@_); } }