ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Re: XML::Generator doesn't like multi-level hash
by Jonathan Stowe other posts by this author
Mar 1 2006 2:29AM messages near this date
view in the new Beta List Site
XML::Generator doesn't like multi-level hash | XML::LibXML parser and external entity expansion?
& XSLT On Mon, 2006-02-27 at 17:00, Aram Mirzadeh wrote:
>  Hello all, 
>  
>  I am having a bit of trouble with XML::Generator.  I
>  am creating a new XML file from a bunch of different
>  SNMP queries that I am storing in a hash.  
>  
>  The problem is that when I generate the XML I get a
>  bunch of HASHREF's in the XML rather than the data
>  points when there is a hash sublevel. 
>  
>  Is this a limitation of XML::Generator?  
>  
>  Here is a sample of Dump and XML output: 
>  
>  $VAR1 = {
>            'osVer' => '#1 SMP Fri Oct 21 04:03:26 EDT
>  2005',
>            'cpuStatsDescr' => 'GenuineIntel, 2992.866
>  MHz',
>            'ntServicePackNumber' => undef,
>            'osRel' => '2.6.12-1.1381_FC3smp, Fedora
>  Core release Rawhide (Rawhide)',
>            'table_ipAdEntAddr' => {
>                                     '1' => '127.0.0.1',
>                                     '0' =>
>  '192.168.1.4'
>                                   },
>            'sysDescr' => 'Linux SystemEDGE Management
>  Agent, Concord Communications, Inc.',
>            'hrMemory' => '1033144',
>            'table_ipAdEntNetMask' => {
>                                        '1' =>
>  '192.168.1.4',
>                                        '0' =>
>  '127.0.0.1'
>                                      },
>            'nodeName' => 'tigger',
>            'numCPU' => '1'
>          };
>  <server osVer="#1 SMP Fri Oct 21 04:03:26 EDT 2005"
>  cpuStatsDescr="GenuineIntel, 2992.866 MHz"
>  osRel="2.6.12-1.1381_FC3smp, Fedora Core release
>  Rawhide (Rawhide)" table_ipAdEntAddr="HASH(0x89f2aec)"
>  sysDescr="Linux SystemEDGE Management Agent, Concord
>  Communications, Inc." hrMemory="1033144"
>  table_ipAdEntNetMask="HASH(0x8667d20)"
>  nodeName="tigger" numCPU="1" />

Yes, XML::Generator isn't really ideal for dealing with pre-existing
data like this, you probably want to look at something like, for
example, XML::Simple:

        use XML::Simple;
         
        $VAR1 = {
                  'osVer' =>  '#1 SMP Fri Oct 21 04:03:26 EDT 2005',
                  'cpuStatsDescr' =>  'GenuineIntel, 2992.866 MHz',
                  'ntServicePackNumber' =>  undef,
                  'osRel' =>  '2.6.12-1.1381_FC3smp, Fedora Core release Rawhide (Rawhide)',
                  'table_ipAdEntAddr' =>  {
                                           '1' =>  '127.0.0.1',
                                           '0' =>  '192.168.1.4'
                                         },
                  'sysDescr' =>  'Linux SystemEDGE Management Agent, Concord Communications, 
Inc.',
                  'hrMemory' =>  '1033144',
                  'table_ipAdEntNetMask' =>  {
                                              '1' =>  '192.168.1.4',
                                              '0' =>  '127.0.0.1'
                                            },
                  'nodeName' =>  'tigger',
                  'numCPU' =>  '1'
                };
         
        print XMLout($VAR1, NoAttr =>  1);
        
Gives you :

        <opt> 
          <cpuStatsDescr> GenuineIntel, 2992.866 MHz</cpuStatsDescr>
          <hrMemory> 1033144</hrMemory>
          <nodeName> tigger</nodeName>
          <ntServicePackNumber> </ntServicePackNumber>
          <numCPU> 1</numCPU>
          <osRel> 2.6.12-1.1381_FC3smp, Fedora Core release Rawhide (Rawhide)</osRel>
          <osVer> #1 SMP Fri Oct 21 04:03:26 EDT 2005</osVer>
          <sysDescr> Linux SystemEDGE Management Agent, Concord Communications, Inc.</sysDesc
r> 
          <table_ipAdEntAddr> 
            <0> 192.168.1.4</0>
            <1> 127.0.0.1</1>
          </table_ipAdEntAddr> 
          <table_ipAdEntNetMask> 
            <0> 127.0.0.1</0>
            <1> 192.168.1.4</1>
          </table_ipAdEntNetMask> 
        </opt> 

You can fiddle with the options to get output more like you want.

/J-- 

This e-mail is sponsored by http://www.integration-house.com/

_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Aram Mirzadeh
Jonathan Stowe

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved