monks,
<level label="SGSN"> <level label="Nokia"> <level label="Card"> <report-def-ref default-operation="unspecified" /> <report-def-ref default-operation="unspecified" /> </level> <level label="Destination Point"> <report-def-ref default-operation="unspecified" /> </level> <level label="IP Interface"> <report-def-ref default-operation="unspecified" /> <report-def-ref default-operation="unspecified" /> </level> <level label="Link Timeslot"> <report-def-ref default-operation="unspecified" /> </level> <level label="Processor"> <report-def-ref default-operation="unspecified"/> </level> <level label="SCP Address"> <report-def-ref default-operation="unspecified"/> </level> <level label="SUB-TREE"> <level label="Three"> <report-def-ref default-operation="unspecified" /> <report-def-ref default-operation="unspecified" /> </level> <level label="Four"> <report-def-ref default-operation="unspecified" /> <report-def-ref default-operation="unspecified" /> </level> </level> </level>
From the above XML file
I would like to get the output like below:- SGSN.Nokia.Card SGSN.Nokia.Destination Point SGSN.Nokia.IP Interface SGSN.Nokia.Link Timeslot SGSN.Nokia.Processor SGSN.Nokia.SCP Address SGSN.SUB-TREE.Three SGSN.SUB-TREE.Four

UPDATE: 1 added more information with the code.
UPDATE: 2 added working code.
#!/usr/bin/perl my $file = "layer.xml"; use XML::Simple; use Data::Dumper; die "Can't find file \"$file\"" unless -f $file; $xml = new XML::Simple(); print "Input file :$file:\n"; # read XML file $data = $xml->XMLin("/apps/inst1/metrica/anthony/3G_SGSN_SGN3/tools/$f +ile"); foreach $keys ( keys %$data ) { next if ( $keys !~ /level/ ); $one = $$data{$keys}{label}; foreach $keys1 ( keys %{$$data{$keys}{level}} ) { $two = $$data{$keys}{level}{label}; foreach $element ( @{$$data{$keys}{level}{$keys1}} ) { print "$one->$two->$$element{label}:\n"; } } }
someone can advise me on making it simpler to traverse the datastructure. I am interested in a tag called 'level' and its 'label'.


In reply to getting required format output from a xml file by greatshots

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.