In xsh, you'd just hash the attributes:
open file.xml ; $h := hash . //@* ; echo { join "\n", keys $h } ;
Similarly, in XML::LibXML:
#! /usr/bin/perl use warnings; use strict; use XML::LibXML; my $xml = 'XML::LibXML'->load_xml( location => 'file.xml' ); my %h; for ($xml->findnodes('//@*')) { $h{ $_->value } = 1; } print "$_\n" for keys %h;
If you only want attributes of elements with no subelements, change the XPath expression to
//*[not(./*)]/@*
Update: Not so simple in XML::Simple:
#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::Simple; my $xml = XMLin('file.xml', ForceArray => 1, KeyAttr => [], ForceContent => 1); my %h; @h{ map values %{ $_->[0] }, grep 'ARRAY' eq ref, map values %{ $_->[0] }, values %{ $xml->{tags}[0] } } = (); say for keys %h;
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
In reply to Re: Extract attributes/values from XML using perl
by choroba
in thread Extract attributes/values from XML using perl / declaring wires in verilog using perl
by gr.d
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |