Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Get a structured tally of XML tags

by graff (Chancellor)
on Apr 24, 2009 at 01:42 UTC ( #759715=snippet: print w/ replies, xml ) Need Help??

Description: Get a quick snapshot of the quantity and structure of elements in an XML file -- useful for getting acquainted with some new XML source, or for confirming expectations about XML data you created. (Yes, it is worthwhile to use XML::Parser in a one-liner...)
perl -MXML::Parser -le '$p=XML::Parser->new(
 Handlers=>{Start=>sub{$k.=".$_[1]";$h{$k}++},
             End=>sub{$k=~s/.$_[1]$//;}});
 $p->parsefile(shift);
 END{print "$h{$_}\t$_" for (sort keys %h)}'   some_file.xml

(Line-breaks added for legibility; the first time I did this, it really was all on one line -- honest!)

Comment on Get a structured tally of XML tags
Download Code

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://759715]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (15)
As of 2015-07-31 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (278 votes), past polls