in reply to XML::Twig question
Just put your xml file as input to the following script, and watch the output. Then you can setup your handlers to filter out whatever you want. The advantage of this approach, is you can feed it huge files and it will process nodes as it finds them.
#!/usr/bin/perl use warnings; use strict; use XML::Parser::PerlSAX; my $parser = new XML::Parser::PerlSAX( Handler => new SampleHandler ); $parser->parse( Source => { SystemId => shift } ); package SampleHandler; sub new { my $self = {}; return bless( $self ); } sub start_document { print "start_document\n"; } sub end_document { print "end_document\n"; } sub start_element { my ( $self, $element ) = @_; my $name = $element->{ Name }; print "start_element: '$name'\n"; while ( my ( $k, $v ) = each( %{ $element->{ Attributes } } ) ) { print " attribute: $k = $v\n"; } } #### a sample sub for parsing a specific node ########### #sub start_element { # my ( $self, $element ) = @_; # my $name = $element->{ Name }; # ## print "start_element: '$name'\n"; # if ( $name eq 'node' ) { # my %node = %{ $element->{ Attributes } }; # print $node{ 'id' }, ' ', $node{ 'lat' }, ' ', $node{ 'lon' }; # } #} ######################################## sub end_element { my ( $self, $element ) = @_; my $name = $element->{ Name }; print "end_element: '$name'\n"; } sub characters { my ( $self, $text ) = @_; my $data = $text->{ Data }; print "characters: '$data'\n"; }
|
|---|