{
my $counter = 'x0000';
sub give_id {
my $x = $_[0];
$x->attr('id', $counter++) unless defined $x->attr('id');
foreach my $c ($x->content_list) {
give_id($c) if ref $c; # ignore text nodes
}
};
give_id($start_node);
}
####
my $tree = HTML::TreeBuilder->new_from_content($html);
$tree->elementify();
my $tagmap = $tree->tagname_map();
ok('Matrix' eq $$tagmap{'h2'}[1]{'_content'}[0], "Got correct title (Matrix)");
##
##
func textfromxml($xp, $xpath) {
my $nodeset = $xp->find($xpath);
my ($text) = XML::XPath::XMLParser::as_string(($nodeset->get_nodelist)[0])
=~ />(.*);
return $text;
}
use XML::XPath;
use XML::XPath::XMLParser;
my $xp = XML::XPath->new(xml => $html);
my $text = textfromxml($xp, '/html/body/div/div/h2[2]');
ok('Matrix' eq $text, "Got correct title (Matrix)");