in reply to XML Node Values Based On Attributes
There are so many different ways to approach this given the size of the toolkit that is libxml2. Here is one native approach.
#!/usr/bin/env perl use strict; use warnings; use XML::LibXML; my $xml = XML::LibXML->load_xml(location => 'locations.xml'); my $nl = $xml->getElementsByLocalName ('Data'); my @text; for my $node ($nl->get_nodelist) { push @text, $node->textContent if 'NAME_2' eq $node->getAttribute +('name'); } print "$_\n" for @text;
I've structured it this way because to me it is pretty easy to follow and clear what is going on. YMMV.
🦛
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML Node Values Based On Attributes
by gpjahn (Novice) on Oct 04, 2022 at 11:12 UTC |