in reply to XML::Simple element handling

Brer Monk,
I wrote a quick little ditty to check out your XML as follows:

#!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; my $stuff=XMLin(); print Dumper($stuff);
When I ran my code I noticed the following oddity in the Data::Dumper output:
$VAR1 = { 'server' => { 'location' => 'atlanta', 'name' => 'cns04-fs16', 'event' => { 'name' => 'diskname > online 6.43 days 10.10.10.10 yellow Thu Mar 30 15:03:16 EST 2006 Disk on cns04-fs16 at WARNING level yellow /mail/vol/cns04-fs16 (93%) has reached the defined disk sp +ace WARNING level (92%) titan atlanta Storage Servers Bluearc Servers basys online 6.44 days 10.10.10.10 yellow Thu Mar 30 15:05:12 2006 yellow node 1 is in status (notUp) yellow TITANPC-2 is in status (notUp) yellow EVS006 is in status (offLine) ' }, 'grouping' => { 'secondary' => 'Mail Filers', 'primary' => 'Storage Servers' } } };

Immediately I suspected that your XML had some sort of error in it and lo and behold, if I changed one line from

<name>disk</ name >
to
<name>disk</name>
eliminating the extra space after the closing tag's slash and when I reran my test I got:
$VAR1 = { 'server' => { 'titan ' => { 'location' => 'atlanta', 'grouping' => { 'secondary' => 'Bluear +c Servers', 'primary' => 'Storage +Servers' }, 'event' => { 'sparedata' => {}, 'entry' => [ { 'color' => ' +yellow', 'desc' => 'n +ode 1 is in status (notUp)' }, { 'color' => ' +yellow', 'desc' => 'T +ITANPC-2 is in status (notUp)' }, { 'color' => ' +yellow', 'desc' => 'E +VS006 is in status (offLine)' } ], 'received_by' => '10.10.1 +0.10', 'name' => 'basys', 'state' => { 'name' => 'onl +ine', 'data' => {} }, 'received_at' => 'Thu Mar + 30 15:05:12 2006', 'length' => '6.44 days', 'color' => 'yellow' } }, 'cns04-fs16' => { 'location' => 'atlanta', 'grouping' => { 'secondary' => 'Ma +il Filers', 'primary' => 'Stor +age Servers' }, 'event' => { 'sparedata' => 'Disk +on cns04-fs16 at WARNING level', 'entry' => { 'color' => + 'yellow', + 'desc' => '/mail/vol/cns04-fs16 (93%) has reached the defined disk s +pace WARNING level (92%)' }, 'received_by' => '10. +10.10.10', 'name' => +'disk', 'state' => { 'name' => +'online', 'data' => +{} }, 'received_at' => 'Thu + Mar 30 15:03:16 EST 2006', 'length' => '6.43 day +s', 'color' => 'yellow' } } } };

That to my eye looks much better.

Now, I must confess that my XML foo is not quite what it should be so I'm not sure if the space after the closing tag's slash is allowed there or not, but I'm not arguing with results. Either the XML was incorrect or there is a parsing issue with XML::Simple.

HTH


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^2: XML::Simple element handling
by linwood (Initiate) on May 10, 2006 at 18:01 UTC
    space must have been added when i was formatting my input. In my xml file the space is not there. with the code below i expect the server elements to be put into an array. this is my perl:
    #!/ms/local/perl5.8.0/bin/perl -w use strict; use XML::Simple; use Data::Dumper; my $bbtmpdata = "bb.xml"; my $xml = new XML::Simple; my $bbevents = $xml->XMLin($bbtmpdata, forcearray=>['server']); print Dumper($bbevents);
          i expect the server elements to be put into an array. this is my perl

      What exactly do you mean by that? Can you post a shortened example of what you want the structure to look like?

      Based on a best guess of what you meant I changed my code to look like:

      #!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; my $stuff=XMLin(undef,KeyAttr=>['server']); print Dumper($stuff);
      which then takes the server element and treats everything enclosed by that as an array. Is that what you were after? Short sample of the structure:
      $VAR1 = { 'server' => [ { 'location' => 'atlanta', 'name' => 'cns04-fs16', 'event' => { 'sparedata' => 'Disk on cns04-fs16 +at WARNING level', 'entry' => { 'color' => 'yellow', 'desc' => '/mail/vol/cns +04-fs16 (9 3%) has reached the defined disk space WARNING level (92%) +' }, 'received_by' => '10.10.10.10', 'name' => 'disk', 'state' => { 'name' => 'online', 'data' => {} }, 'received_at' => 'Thu Mar 30 15:03: +16 EST 200 6', 'length' => '6.43 days', 'color' => 'yellow' }, 'grouping' => { 'secondary' => 'Mail Filers', 'primary' => 'Storage Servers' } },


      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg