in reply to HTML::TreeBuilder::XPath finding attribute values

If your query returns an attribute, you can only call attribute methods on it. If your query returns a node, you can only call node methods on it.

In your case, you can either check the type of the returned value or you can look at your query and then fetch the appropriate thing. The latter is what I do in HTML::Selector::XPath:

my $attr; if ($selector =~ s!/?\@(\w+)$!!) { $attr = $1; }; ... my @nodes; if (! defined $attr) { @nodes = map { $_->as_trimmed_text } $tree->findnodes($sel +ector); } else { @nodes = $tree->findvalues("$selector/\@$attr"); };