Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: perl script to print xml data like this

by afresh1 (Hermit)
on Oct 04, 2011 at 03:07 UTC ( #929433=note: print w/ replies, xml ) Need Help??


in reply to perl script to print xml data like this

I'm having a very hard time deciphering your question but I think you (may) want something like this. It does not keep the exact XML formatting but that is something that is lost when XML::Simple parses it.

use strict; use warnings; use XML::Simple; my $xml = new XML::Simple; my $data = $xml->XMLin( \*DATA ); my %by_code; foreach my $dtc ( @{ $data->{DTC} } ) { push @{ $by_code{ $dtc->{TroubleCode} } }, $dtc; } foreach my $code ( sort { $a <=> $b } keys %by_code ) { print "trouble code: $code\n"; print "description:\n"; print map { $xml->XMLout( $_, RootName => 'DTC', NoAttr => 1, ) } @{ $by_code{$code} }; } __DATA__ <xml> Removed by request. </xml>
l8rZ,
--
andrew


Comment on Re: perl script to print xml data like this
Download Code
Re^2: perl script to print xml data like this
by veerubiji (Sexton) on Oct 04, 2011 at 08:28 UTC

    Hi afreshl, thanks for your reply, and sorry for replying on both sites. because i cant post clearly there.

    Argument "'\x{32}\x{30}..." isn't numeric in sort "
    at foreach my $code (sort....) line. i am getting this argument in th second for loop frist line and your code is working but i am getting XML data under description is not like original format, it displying in diffrent order bottom comments to up and upper comments to down.

      The error does not occur with the sample so the actual xml is apparently different than what you provided. To get rid of the sorting error, just don't sort the output.

      14 foreach my $code ( keys %by_code ) {

      If you need the output exactly as it was, you will need to use a solution other than XML::Simple. As I said:

      It does not keep the exact XML formatting but that is something that is lost when XML::Simple parses it.
      l8rZ,
      --
      andrew

        thanks for your reply and suggestion i got my answer.

Re^2: perl script to print xml data like this
by veerubiji (Sexton) on Oct 06, 2011 at 18:37 UTC

        Done.

        l8rZ,
        --
        andrew
          Thank you very much.

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: note [id://929433]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (10)
    As of 2014-08-30 06:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (291 votes), past polls