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

In reply to XML::Simple and arrays by J9

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.