Appologies if this turns out to be a long post.
I have the following xml file:..
<?xml version="1.0"?>
<!-- This is XML for the Notify Mapping -->
<map>
<CI name="ABC">
<recipient id="Usr-One">
<alert method="SMS" dest="+44123456789" st="" et="">
<enable>Y</enable>
</alert>
<alert method="EMAIL" dest="usr-one@nowhere.co.uk" st="" e
+t="">
<enable>Y</enable>
</alert>
</recipient>
<recipient id="User-two">
<alert method="SMS" dest="+44987654321" st="" et="">
<enable>Y</enable>
</alert>
<alert method="EMAIL" dest="user-two@anywhere.co.uk" st=""
+ et="">
<enable>Y</enable>
</alert>
</recipient>
</CI>
<CI name="DEF">
<recipient id="Usr-One">
<alert method="SMS" dest="+44123456789" st="" et="">
<enable>Y</enable>
</alert>
</recipient>
</CI>
</map>
Basically what I want to do is, if I have a var that matches the CI name I want to (at this point) print out EACH
alert method and
dest. (I am not doing anything with either
st or
et yet.)
So this is what I have so far ... (
but I cant get any further)
use strict;
use warnings;
use XML::Simple;
#use Data::Dumper; # I put this here to see what the hash looks like
my $check = "ABC";
my $alert_config_file = "C:/Path to XML/AlertCIMap.xml";
my $XMLSimple = XML::Simple->new(forcearray => 1, keyattr => {});
eval { $rules = $XMLSimple->XMLin("$alert_config_file")};
if ($@) {
print "Problems Reading $alert_config_file: $@\n";
exit;
}
#print Dumper($rules);
if (&CI_Exists($check)) {
print "Matched\n";
} else {
print "NOT FOUND\n";
}
## SUB ROUTINES ##
sub CI_Exists #Check if CI exists in Mapping
{
my $chk = shift;
my $rc = 0;
#Foreach name in xml look for match
my $ci = $rules->{CI};
foreach my $n(@$ci) {
if ($n->{name} eq $chk){
print "Chk = $chk\n"; #Just for testing so I can s
+ee stuff is happening
#THIS NEXT LINE IS CAUSING ME FRUSTRATION...
my $rec_list = $n->{name}->{recipients}; #List of
+Recepients
foreach my $recipient(@$rec_list) {
#foreach Alert create file.
print "Recipient = $recipient\n";
my $alert_list = # What should go here
+..?? List of Alerts
foreach my $alert($alert_list){
print"I Would Send a $alert to $recipient\n";
}
}
$rc = 1;
last;
}
}
return($rc);
}
How can I check each recipient and, foreach recipient check each alert method..?
Is there a better way to layout the xml file as I have control over this?
Many Many thanks,
J9