Sporti69 has asked for the wisdom of the Perl Monks concerning the following question:
But I don't know ( I know, it's simple but I don't get it) how to parse an xml looking like this...<root> <SUB CLASSNAME="SUB1"> <Element1 Type="Type1">Type 1 value</Element1> <Element2 Type="Type2">Type 2 value</Element2> </SUB> </root>
How do I reach Type and Content now ?? (My working script is linked at the bottom with full xml) This is a piece of my code:<SUB CLASSNAME="SUB1"> <INNERSUB CLASSNAME="INNERSUB1"> <Element1 Type="Type1">Content</element1> <Element2 Type="Type2">Content</element2> </INNERSUB> </SUB>
The complete working script is at: Script file and an example xml as well : The XML And even as a ZIP/RAR at : Rar Package Feel free to dowload and reuse. But please help me outmy $xs1 = XML::Simple->new(); my $doc = $xs1->XMLin($file, keyattr=>['CLASSNAME'], ForceContent=>1, +ForceArray=>1); use Data::Dumper; local $Data::Dumper::Indent=1; for my $sub ( sort keys %{ $doc->{SUB} } ){ $rowCount = $tellerR; $worksheet->Cells($rowCount, $colCount)->{Value} = $sub; for my $elem ( sort keys %{ $doc->{SUB}{$sub} } ){ for my $element ( @{ $doc->{SUB}{$sub}{$elem} } ){ $worksheet->Cells($rowCount, $colCount)->{Value} = $$element{Type}; $worksheet->Cells($rowCount, $colCount)->{Value} = $$element{content}; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Newbie XML Simple reference
by ig (Vicar) on Nov 03, 2008 at 18:58 UTC | |
|
Re: Newbie XML Simple reference
by toolic (Bishop) on Nov 03, 2008 at 19:16 UTC | |
|
Re: Newbie XML Simple reference
by grantm (Parson) on Nov 03, 2008 at 21:57 UTC | |
by Sporti69 (Acolyte) on Nov 05, 2008 at 09:57 UTC | |
by Sporti69 (Acolyte) on Nov 05, 2008 at 10:44 UTC | |
by Anonymous Monk on Nov 05, 2008 at 11:59 UTC | |
by Sporti69 (Acolyte) on Nov 05, 2008 at 13:10 UTC | |
|
Re: Newbie XML Simple reference
by Anonymous Monk on Nov 04, 2008 at 11:18 UTC | |
by Sporti69 (Acolyte) on Nov 05, 2008 at 09:56 UTC |