shak4031's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
New Members
Active Posts:
4 (0.01 per day)
Joined:
22-May 12
Profile Views:
163
Last Active:
User is offline May 24 2012 11:00 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   shak4031 has not set their status

Posts I've Made

  1. In Topic: Trouble parsing XML via perl

    Posted 24 May 2012

    Thank you for the save, most of my responses would have been a single record. I will employ option 1 that ou recommended.
  2. In Topic: Trouble parsing XML via perl

    Posted 23 May 2012

    I was able to make it work.

    #!/usr/bin/env perl    
    
    use strict;    
    
    use warnings;    
    
    use 5.010;    
    
    use XML::Simple;    
     
    my $xml = join '', <DATA>;    
       
    # create object
        $xs1 = new XML::Simple (KeyAttr=>[]);
    
        # read XML data
        my $xmlResp = $xs1->XMLin($xml);
    
        # dereference hash ref
        # access <DeviceInformation> array
        foreach $e (@{$xmlResp->{DeviceInformation}})
        {
            print "Devicename: ".$e->{DeviceName}, "\n";
            print "DeviceID: ".$e->{DeviceId}, "\n";
        }
    
    __DATA__    
    <?xml version="1.0" encoding="utf-8"?>    
    <ArrayOfDeviceInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
     <DeviceInformation>  
      <DeviceId>96989</DeviceId>  
      <DeviceName>snoa449-acc02-6509</DeviceName>  
      <IPAddress>192.166.45.9</IPAddress>  
      <Status>Operational</Status>  
      <autoReady>0</autoReady>  
      <LBCode>A448</LBCode>  
      <REMSCode>12492</REMSCode>  
      <BuildingName />  
      <Address>Tordenskioldsgate 8-10, Po Box 1481 Vika</Address>  
      <City>Oslo</City>  
      <PostalCode>N-0116</PostalCode>  
      <County />  
      <Country>Norway</Country>  
      <Region>WESTERN EUROPE</Region>  
     </DeviceInformation>  
     <DeviceInformation>  
      <DeviceId>96859</DeviceId>  
      <DeviceName>snoa448-acc02-6509</DeviceName>  
      <IPAddress>169.166.79.6</IPAddress>  
      <Status>Operational</Status>  
      <autoReady>0</autoReady>  
      <LBCode>A448</LBCode>  
      <REMSCode>12492</REMSCode>  
      <BuildingName />  
      <Address>Tordenskioldsgate 8-10, Po Box 1481 Vika</Address>  
      <City>Oslo</City>  
      <PostalCode>N-0116</PostalCode>  
      <County />  
      <Country>Norway</Country>  
      <Region>WESTERN EUROPE</Region>  
     </DeviceInformation>  
    </ArrayOfDeviceInformation> 
    
    


    Output:

    Devicename: snoa449-acc02-6509
    DeviceID: 96989
    Devicename: snoa448-acc02-6509
    DeviceID: 96859
  3. In Topic: Trouble parsing XML via perl

    Posted 23 May 2012

    Thank you for the reply, i was able to get the program to work. What i am looking for is help with how to deal with multiple records in the XML. How to get all the "DeviceName"'s and "DeviceID"'s when there are multiple records. I am able to use the index to target one but i don't know how to determine how many records there are.

    #!/usr/bin/env perl  
    
    use strict;  
    use warnings;  
    use 5.010;  
    use XML::Simple;  
    
    my $xml = join '', <DATA>;  
    
    my $tree = XMLin($xml);  
    
    say $tree->{DeviceInformation}->[0]->{DeviceName};  
    
    __DATA__  
    
    <?xml version="1.0" encoding="utf-8"?>  
    <ArrayOfDeviceInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      <DeviceInformation>
        <DeviceId>96989</DeviceId>
        <DeviceName>snoa449-acc02-6509</DeviceName>
        <IPAddress>192.166.45.9</IPAddress>
        <Status>Operational</Status>
        <autoReady>0</autoReady>
        <LBCode>A448</LBCode>
        <REMSCode>12492</REMSCode>
        <BuildingName />
        <Address>Tordenskioldsgate 8-10, Po Box 1481 Vika</Address>
        <City>Oslo</City>
        <PostalCode>N-0116</PostalCode>
        <County />
        <Country>Norway</Country>
        <Region>WESTERN EUROPE</Region>
      </DeviceInformation>
      <DeviceInformation>
        <DeviceId>96859</DeviceId>
        <DeviceName>snoa448-acc02-6509</DeviceName>
        <IPAddress>169.166.79.6</IPAddress>
        <Status>Operational</Status>
        <autoReady>0</autoReady>
        <LBCode>A448</LBCode>
        <REMSCode>12492</REMSCode>
        <BuildingName />
        <Address>Tordenskioldsgate 8-10, Po Box 1481 Vika</Address>
        <City>Oslo</City>
        <PostalCode>N-0116</PostalCode>
        <County />
        <Country>Norway</Country>
        <Region>WESTERN EUROPE</Region>
      </DeviceInformation>
    </ArrayOfDeviceInformation>
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

shak4031 hasn't added any friends yet.

Comments

shak4031 has no profile comments yet. Why not say hello?