Paulux has asked for the wisdom of the Perl Monks concerning the following question:
At the state of the art, I can't change my parsing module, so I have to solve this problem. B/R and thanx a lot.#!/usr/bin/perl use XML::Parser; @files = <$plrepository/*.xml>; foreach $xmlfile (@files) { #something is omitted $p2 = new XML::Parser(Handlers => {Start => \&handle_start, End => \&handle_end, Char => \&handle_char}); $p2->parsefile($xmlfile); } sub handle_start { my ($pkg,$element,%attr) = @_; $current_element = $element; if ( $element =~ /Header/i ) { $Number=$attr{Number}; open (OUT, ">$outputfile") or die "No file"; } $Number=''; # I empty the variable for the next Number in the fil +e #something is omitted } sub handle_end { my ($pkg,$element,%attr) = @_; if ( $element =~ /Header/i ) { print OUT $Number,"$separator\n"; print "\tNumber ". $Number . "\n"; close (OUT); } #something is omitted $Number=''; # I empty the variable for the next Number in the fil +e } sub handle_char { my $text = $_[1]; if ( $current_element =~ /^Number$/i ) { ($text !~ /^\s*$/) && ($Number .= $text); #|-> buffer text } #something is omitted }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Another problem with XML parser
by toolic (Bishop) on Nov 10, 2009 at 13:50 UTC | |
by Paulux (Acolyte) on Nov 10, 2009 at 14:07 UTC | |
|
Re: Another problem with XML parser
by gmargo (Hermit) on Nov 10, 2009 at 17:18 UTC | |
by Paulux (Acolyte) on Nov 11, 2009 at 09:07 UTC | |
by Your Mother (Archbishop) on Nov 12, 2009 at 03:42 UTC | |
by Paulux (Acolyte) on Nov 23, 2009 at 11:26 UTC | |
by Anonymous Monk on Nov 16, 2009 at 10:23 UTC | |
by Your Mother (Archbishop) on Nov 17, 2009 at 05:42 UTC | |
by gmargo (Hermit) on Nov 16, 2009 at 13:44 UTC | |
| |
by Paulux (Acolyte) on Nov 16, 2009 at 11:54 UTC |