Hi,

I am stuck at a puppet provider where I need to read data from xml.

Data which needs to get parsed:

    <AR>
      <AR_ID><![CDATA[8]]></AR_ID>
      <IP><![CDATA[172.16.100.208]]></IP>
      <MAC><![CDATA[02:00:ac:10:64:d0]]></MAC>
      <SIZE><![CDATA[1]]></SIZE>
      <TYPE><![CDATA[IP4]]></TYPE>
      <USED_LEASES>0</USED_LEASES>
      <LEASES/>
    </AR>
    <AR>
      <AR_ID><![CDATA[9]]></AR_ID>
      <IP><![CDATA[172.16.100.209]]></IP>
      <MAC><![CDATA[02:00:ac:10:64:d1]]></MAC>
      <SIZE><![CDATA[1]]></SIZE>
      <TYPE><![CDATA[IP4]]></TYPE>
      <USED_LEASES>0</USED_LEASES>
      <LEASES/>
    </AR>


Expected result:

:addressrange => 
  { ‘1' =>
    { ‘ip' => ‘172.16.100.208’, ‘mac' => ’02:00:ac:10:64:d0’ },
     ‘2' => 
    { ‘ip' =>  ‘172.16.100.209’, ‘mac' => ’02:00:ac:10:64:d1’ }
  }


Actual code (Note: I was never good at coding an will never be):

vnets.collect do |vnet|
  new(
    :addressrange => Hash[vnet.xpath('./AR_POOL/AR/AR_ID').collect { |ar| 
[ar.text, ar.xpath('..').collect { |singlear| singlear.xpath('./*').collect { 
|arvalue| {arvalue.name, arvalue.text} } } ] } ]
  )
end


But this code return:
:addressrange=>
     {"9"=>
       [[{"AR_ID"=>"9"},
         {"IP"=>"172.16.100.209"},
         {"MAC"=>"02:00:ac:10:64:d1"},
         {"SIZE"=>"1"},
         {"TYPE"=>"IP4"}]],
      "8"=>
       [[{"AR_ID"=>"8"},
         {"IP"=>"172.16.100.208"},
         {"MAC"=>"02:00:ac:10:64:d0"},
         {"SIZE"=>"1"},
         {"TYPE"=>"IP4"}]],

What would be proper code to build the hash as expected?

Thanks,

Martin

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/40FA8BCE-74C4-478C-9648-8FE26365BFF9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to