I'm trying to save HTTPs with IDs, like this one
https://hostname:9060/ers/config/networkdevice/1
in 'output.csv'. After that I want use these links in my get requests to get more Information from Management System about device.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ns3:searchResult total="3" xmlns:ns5="ers.ise.cisco.com" xmlns:ers-v2="ers-v2"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns3="v2.ers.ise.cisco.com">
<ns3:resources>
<ns5:resource id="1"
name="Device1">
<link rel="self" href="https://hostname:9060/ers/config/networkdevice/1"
type="application/xml"/>
</ns5:resource>
<ns5:resource id="2"
name="Device2">
<link rel="self" href="https://hostname:9060/ers/config/networkdevice/2"
type="application/xml"/>
</ns5:resource>
<ns5:resource id="3"
name="Device3">
<link rel="self" href="https://hostname:9060/ers/config/networkdevice/3"
type="application/xml"/>
</ns5:resources>
</ns3:resources>
</ns3:searchResult>
But after using my Perl Script, my file is empty.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use XML::Simple;
#NOTE: Update this to contain my elements in CSV
my @Fields = qw{id};
my $xml = XMLin('Get_All_Prime.xml', ForceArray => ['link']);
foreach my $link ( @{ $xml->{link} } ) {
print Dumper $link;
foreach my $link ( @{ $xml->{link} } ) {
print join( ',', @{ $link->{href} }{@Fields} ) . "\n";
}
}
open(my $out, '>', 'output.csv') or die "Output: $!\n";
foreach my $link ( @{ $xml->{link} } ) {
print $out join ( ',', @{$link->{href} }{@Fields} ) . "\n";
}
I'm not sure, that I use the right tag
ForceArray => ['link']
But what should I use in this case?