use strict; use warnings; no warnings 'uninitialized'; use XML::Rules; my $parser = XML::Rules->new( rules => { _default => 'raw extended', start_element => sub { my ($tag,$attr,$context,$parents,$parser) = @_; print {$parser->{parameters}[( exists $attr->{':user_id'} +? 0 : 1 )]} $parser->ToXML( $tag, $attr); } } ); open my $FH1, '>', 'c:\temp\test1.xml'; open my $FH2, '>', 'c:\temp\test2.xml'; print $FH1 "<root>\n"; print $FH2 "<root>\n"; $parser->parse( \*DATA, [$FH1, $FH2]); print $FH1 "\n</root>\n"; print $FH2 "\n</root>\n"; __DATA__ <root> <start_element> <element_num>1</element_num> <child>MyChild</child> </start_element> <start_element> <element_num>2</element_num> <child>MyChild</child> <user_id>MyUser</user_id> </start_element> <start_element> <element_num>3</element_num> <child>MyChild</child> </start_element> </root>
Jenda
Enoch was right!
Enjoy the last years of Rome.
In reply to Re: Need to process a XML file through Perl
by Jenda
in thread Need to process a XML file through Perl
by paragkalra
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |