XML with attributes



In my little piece of code I parse a XML, but since I need to do the same thing in 3 places, I would like to make a subroutine for each time... but I need to pass the current node I'm working in as an argument, being beyond my current (worthless) skills to access the current nodes child nodes.... here's and example of my code:



foreach $day ($doc->findnodes('/my/current/path')){
@atts = $day -> getAttributes();
foreach $at (@atts) {
$na = $at -> getName();
$va = $at -> getValue();
if ($va eq "today"){
#------ my repeated code begins here -----
foreach $thing ($day->findnodes('child_nodes_im_looking_for')){
#----- do a lot of stuff
}
#------ my repeated code ends here -----
}
if ($va eq "tomorrow"){
#same repeated code
}
if ($va eq "some_other_day"){
#same repeated code.... again
}
#for other days... do nothing

}


how should I pass my current node to the subroutine so I can access its child nodes directly from the routine?


No comments:

Post a Comment