in reply to Get data from an XML file heading

It doesn't look like XML to me.

It does to me, unless you're not showing everything.

If not, I guess a RegEx would be the way to go.

No, please don't!! Parsing HTML/XML with Regular Expressions

use warnings; use strict; use XML::LibXML; my $xml = <<'END_XML'; <root> <result_summary total_records="594" total_pages="3" current_page="1" records_this_page="250" download_key="xmxnxnxnxnxnxnxnxnx" time_start="2020-02-19 15:50:55" feed_version="1.44" /> </root> END_XML my $dom = XML::LibXML->load_xml(string => $xml); my @nodes = $dom->findnodes('//result_summary'); die "Failed to find exactly one result_summary node" unless @nodes==1; my %attrs = %{ $nodes[0] }; use Data::Dumper; print Dumper(\%attrs); __END__ $VAR1 = { 'total_records' => '594', 'feed_version' => '1.44', 'time_start' => '2020-02-19 15:50:55', 'download_key' => 'xmxnxnxnxnxnxnxnxnx', 'total_pages' => '3', 'records_this_page' => '250', 'current_page' => '1' };

Replies are listed 'Best First'.
Re^2: Get data from an XML file heading
by nachtmsk (Acolyte) on Feb 20, 2020 at 15:58 UTC
    Thanks. I didn't think it looked like XML Because it didn't have an ending and it has multiple values for one, node, I guess you would call it.

    I thought XML looks more like below...

    <myId>757</myId> <address> 445 smith</address>

    The data I get at the top of the file has one node name "result_summary" no ending tag/node and multiple values within the node.

    Thanks for the solution though.
      I didn't think it looked like XML Because it didn't have an ending and it has multiple values for one, node, I guess you would call it.

      It's known as an "empty-element" tag, <element /> is equivalent to <element></element>, and the values within the tag itself are attributes. See e.g. https://www.w3schools.com/xml/.

        Thanks again.

        One more thing. Not sure if I understand what this line of code is doing. It looks like it's taking the first element of the array called 'nodes' and converting it into a hash called attrs. Is that correct?

        my %attrs = %{ $nodes[0] };