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}; } }
In reply to Newbie XML Simple reference by Sporti69
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |