#!/usr/bin/perl -- use strict; use warnings; use XML::Simple; my $xml = <<'__XML__'; <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> __XML__ my $xs1 = XML::Simple->new(); my $doc = $xs1->XMLin($xml, keyattr=>['CLASSNAME'], ForceContent=>1, F +orceArray=>1); use Data::Dumper; local $Data::Dumper::Indent=1; print Dumper( $doc ); for my $sub ( keys %{ $doc->{SUB} } ){ print "Processing $sub\n"; for my $elem ( keys %{ $doc->{SUB}{$sub} } ){ print "Processing $elem\n"; for my $element ( @{ $doc->{SUB}{$sub}{$elem} } ){ print "$element Type: $$element{Type}\n"; print "$element content: $$element{content}\n"; } } } __END__ $VAR1 = { 'SUB' => { 'SUB3' => { 'Element2' => [ { 'Type' => 'Henry', 'content' => 'Some stuff' } ], 'Element1' => [ { 'Type' => 'Star', 'content' => 'content 1' } ] }, 'SUB2' => { 'Element2' => [ { 'Type' => 'Type2', 'content' => 'Type 2 value' }, { 'Type' => 'Type3', 'content' => 'Type 5 value' } ], 'Element1' => [ { 'Type' => 'Type1', 'content' => 'Type 1 value' } ] }, 'SUB1' => { 'Element2' => [ { 'Type' => 'Type2', 'content' => 'Type 2 value' } ], 'Element1' => [ { 'Type' => 'Type1', 'content' => 'Type 1 value' } ] } } }; Processing SUB3 Processing Element2 HASH(0x1ba4eb4) Type: Henry HASH(0x1ba4eb4) content: Some stuff Processing Element1 HASH(0x1ba4f44) Type: Star HASH(0x1ba4f44) content: content 1 Processing SUB2 Processing Element2 HASH(0x1ba4bfc) Type: Type2 HASH(0x1ba4bfc) content: Type 2 value HASH(0x1ba4c08) Type: Type3 HASH(0x1ba4c08) content: Type 5 value Processing Element1 HASH(0x1ba4c8c) Type: Type1 HASH(0x1ba4c8c) content: Type 1 value Processing SUB1 Processing Element2 HASH(0x1ba4980) Type: Type2 HASH(0x1ba4980) content: Type 2 value Processing Element1 HASH(0x1ba4a10) Type: Type1 HASH(0x1ba4a10) content: Type 1 value

In reply to Re^2: XML to Excel : not Unique ?? by Anonymous Monk
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.