Sorry, I thought this would be enough, but I'll post my complete code now. The problem is not actually the XML
because with unique elements it does work.
<ROOT> <SUB CLASSNAME="SUB1"> <Element1 Type="Type1">Type 1 value</Element1> <Element2 Type="Type2">Type 2 value</Element2> </SUB> <SUB CLASSNAME = "SUB2"> <Element1 Type="Type1">Type 1 value</Element1> <Element2 Type="Type2">Type 2 value</Element2> <Element2 Type="Type3">Type 5 value</Element2> </SUB> <SUB CLASSNAME = "SUB3"> <Element1 Type="Star">content 1</Element1> <Element2 Type="Henry">Some stuff</Element2> </SUB> </ROOT>
This fails on the third element of the second node: <element2>
This is the COMPLETE perl script:
#! /usr/bin/perl use strict; use warnings; use Data::Dumper; use Cwd; use Win32::OLE; use XML::Simple; my $file = 'dataFile.xml'; my $xs1 = XML::Simple->new(); my $doc = $xs1->XMLin( $file, keyattr=>['CLASSNAME'], ForceContent=>1 +); my %subroutines = %{$doc->{SUB}}; my $application = Win32::OLE->new("Excel.Application"); my $workbook = $application->Workbooks->Add(); my $worksheet = $workbook->Worksheets(1); my $rowCount = 2; my $colCount = 2; my $colspan = 1; foreach my $this_routine ( sort keys %subroutines ) { my $element_count = scalar( keys %{$subroutines{$this_routine}} ); $worksheet->Cells($rowCount, $colCount)->{Value} = $this_routine; $rowCount++; foreach my $this_type (sort keys %{$subroutines{$this_routine}} ) { if ( exists $subroutines{$this_routine}-> {$this_type}->{Type}) { $worksheet->Cells($rowCount, $colCount)->{Value} = $this_type; $colCount++; } $rowCount--; }
Would be great if you guys found what is wrong. Deleting the element2 in the SUB2 will generate an excel file in your current directory.

In reply to Re: XML to Excel : not Unique ?? by Sporti69
in thread XML to Excel : not Unique ?? by Sporti69

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.