@MYCLASS::ISA = qw(XML::SAX::Base); sub static_handler { $self->set_handler(XML::LibXML::SAX::Builder->new()); } sub result { $self->get_handler()->result(); # will return a DOM structure } sub found_token { my ($self, $tag, $attributes) = @_; $self->check_active_tokens(); # and end them if required my $e = _element($tag); for my $key ( keys %$attributes ) { _add_attribute($e, $key, $attributes->{$key} ); } $self->start_element($e); } sub check_active_token { # this allows no nested tags. # tag soup logic should end up in this function foreach my $tag ( @{$self->{_TOKENS_}} ) { $self->end_element( _element($tag, 1) ); } } # the following functions I stole from Matt's code ;) # it simplifies the handling of SAX data structures for # those cases that don't require namespace handling. sub _element { my ($name, $end) = @_; return { Name => $name, LocalName => $name, $end ? () : (Attributes => {}), NamespaceURI => '', Prefix => '', }; } sub _add_attrib { my ($el, $name, $value) = @_; $el->{Attributes}{"{}$name"} = { Name => $name, LocalName => $name, Prefix => "", NamespaceURI => '', Value => $value, }; return $el; }