Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: getting required format output from a xml file

by Hofmator (Curate)
on Nov 08, 2006 at 10:27 UTC ( #582846=note: print w/replies, xml ) Need Help??


in reply to getting required format output from a xml file

Here is a solution using XML::Twig. Please feel free to improve on it as I'm new to XML::Twig ...
use XML::Twig; my $twig= new XML::Twig( start_tag_handlers => { 'level' => \&start_level }, twig_handlers => { 'level' => \&end_level }, ); $twig->parsefile($file); my @levels; sub start_level { push @levels, $_[1]->{att}{label}; print join ('.', @levels), "\n" if @levels == 3 } sub end_level { pop @levels; }

-- Hofmator

Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://582846]
help
Chatterbox?
[Eily]: I just wrote a oneliner to solve a (non perl) colleague's problem, and it worked on the first try
[Eily]: and he wasn't impressed
1nickt adds gingersnaps to the platter on the sideboard.
[Eily]: sure it was a pretty standard one liner (of the $h{$1} = $2 if /regex/; END { pp \%h; } variety), but he's not supposed to know that!

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2017-04-26 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (482 votes). Check out past polls.