Thanks. That was it. The manual page for XML::XPath::Node::Element had most of what was needed.

I'm still puzzled about the data structures, however.

I'm getting XML::XPath::Node::Attribute=REF(0x55bcf3d63f30) instead of 'href' below. The manual page says it should return a list.

#!/usr/bin/perl use HTML::Tidy; use XML::XPath; use strict; use warnings; my $body; while(my $line = <DATA>) { $body .= $line; } my $tidy = HTML::Tidy->new({output_xml => 1,numeric_entities=>1}); my $clean = $tidy->clean($body); my $parser = XML::XPath->new(xml => $clean); my $set = '//p/a'; my $nodes = $parser->find($set); foreach my $node ($nodes->get_nodelist) { print "\n"; print $node->getName(),"\n"; # this next line is wrong print join(", ", $node->getAttributeNodes),"\n"; } exit(0); __DATA__ <!doctype html> <html class="no-focus-outline no-js " lang="en-US" data-modal-active="true"> <head> <title>test</title> </head> <body> <h1>test&nbsp;heading</h1> <div> <p>paragraph one <a href="https://example.com/one/two.html">one</a> example.</p> <p>paragraph two <a href="https://example.com/two/three.html">another</a> example.</p> </div> </body> </html>

In reply to Re^2: Data structure question from XML::XPath::XMLParser by mldvx4
in thread Data structure question from XML::XPath::XMLParser by mldvx4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.