Thanks for the advice. The script has evolved again into a working one. Everything works without one xml tag in the script.

thank you all for helping me. Not only in this node.

#!/usr/bin/perl -- use strict; use warnings; use Cwd; use Win32::OLE; use XML::Simple; my $dir = cwd(); opendir(DIR, "."); my @file = grep(/\.xml$/,readdir(DIR)); closedir(DIR); use Data::Dumper; local $Data::Dumper::Indent=1; #print Dumper($doc); ################### #my %hash = ( # key1 => 'ArraySite', # key2 => 'IOPort', # key3 => 'AddressGroup', # key4 => 'LSS', # key5 => 'Array', # key6 => 'Rank', # key7 => 'ExtentPool', # key8 => 'Volume', # key9 => 'StorageEnclosure', # key10 => 'VolumeGroup', # ); # # for my $key ( keys %hash ) { # my $value = $hash{$key}; # print "$key => $value\n"; # } ############## my $xs1 = XML::Simple->new(); my $doc = $xs1->XMLin($file[0], keyattr=>[], ForceContent=>1, ForceArr +ay=>1); for my $sub1 ( sort keys %{ $doc } ){ my $count = scalar keys %{ $doc }; print "\n$sub1\t"; for (my $i=0; $i <= $count; $i++) { for my $sub2 ( sort keys %{ $doc->{$sub1}[$i] } ){ my $count2 = @{$doc->{$sub1}[$i]{$sub2}}; #print "\n\t\t".$count2."\t".$sub2; for (my $j=0; $j <= $count2; $j++) { for my $sub3 ( sort keys %{ $doc->{$sub1}[$i]{$sub2}[$ +j] } ){ my $count3 = @{$doc->{$sub1}[$i]{$sub2}[$j]{$sub3} +}; print "\n\t$sub2\t$sub3($count3)"; for (my $k=0; $k <= $count3; $k++) { print "\n"; for my $sub4 ( sort keys %{ $doc->{$sub1}[$i]{ +$sub2}[$j]{$sub3}[$k] } ){ print "\n\t\t\t$sub4 : "; print $doc->{$sub1}[$i]{$ +sub2}[$j]{$sub3}[$k]{$sub4}; } } } } } } }
XML
<A> <B> <C> <element type="k" name="p" online="yes"/> <element type="i" name="e" online="yes"/> </C> <D> <element type="kd" name="pd" online="no"/> <element type="id" name="ed" online="yes"/> <element type="yd" name="zd" online="no"/> </D> </B> <Z> <C> <element type="k" name="z" online="yes"/> <element type="t" name="p" online="yes"/> </C> <E> <element type="kd" name="pd" online="no"/> <element type="id" name="ed" online="yes"/> </E> </Z> </A>
But I could still use some help... When I add an attribute to lets say tag B my code fails all of a sudden ... Can someone tell me why / advise or point out a solution... The error I get is "Can't use string ("value of attribute") as an ARRAY ref while "strict refs""

Thanks so much !


In reply to Re^2: XML Attribute vs Element by Sporti69
in thread XML Attribute vs Element 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.