Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 chilling in the Monastery: (8)
As of 2014-10-02 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls