in reply to XML::Simple parsing
Did you think you could avoid the inevitable? Here is how someone from New Hampshire would solve this using XML::Twig! I guess grantm will have more on the way you use XML::Simple ;--)
XML::Twig is quite appropriate here because it lets you specify quite easily that you only want to process header elements with a specific attribute name, and it will only load the relevant part of the document, instead of the entire thing.
#!/usr/bin/perl -w -l use strict; use XML::Twig; my $name= live_free() or die; my $t= XML::Twig->new( twig_roots => { qq{header[\@name="$name"]} => \&print_content + }, ); $t->parse( \*DATA); sub print_content { my( $t, $header)= @_; print join( "\n", map { $_->text } $header->children); } sub live_free { return shift @ARGV; } __DATA__ <?xml version="1.0"?> <!-- This is XML for the Header Mapping --> <map> <header name="ABCstatus"> <act>WTO</act> </header> <header name="ABCevent"> <act>WTO</act> <act>Call</act> </header> <header name="DEF-Call"> <act>Call</act> </header> <header name="Unknown"> <act>WTO</act> <act>SMS</act> <act>NetSend</act> </header> </map>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: XML::Simple parsing
by AcidHawk (Vicar) on Oct 23, 2002 at 15:11 UTC | |
by mirod (Canon) on Oct 23, 2002 at 15:23 UTC |