Hello,
I've read the docs on XMLnode but am having some problems.
I am loading an dcr from a callout and trying to iterate through 4 nested replicant items.
My question is surrounding syntax of how to address a single item within a replicant and the syntax of how to iterate through replciant items and nested replicant items.
The structure of the DCR is the following. Each level of replicant is nested within the previous level.
Level 1(Replicant)
Link Text (item)
Link URL (item)
Link Target (item)
Level 2 (Replicant)
Link Text (item)
Link URL (item)
Link Target (item)
Level 3 (Replicant)
Link Text (item)
Link URL (item)
Link Target (item)
Level 4 (Replicant)
Link Text (item)
Link URL (item)
Link Target (item)
my $rootnode = TeamSite::XMLnode->new($xml);
my $intLevel1Ctr = 0;
# Iterate Level 1
foreach my $level_1 ($rootnode->get_node_list('Level 1')){
# These are items within the replicant and how I reference them
# Is this the correct syntax
my $linkText = $rootnode->value("Level 1[$intLevel1Ctr].Link Text");
my $linkURL = $rootnode->value("Level 1[$intLevel1Ctr].Link URL");
my $linkTarget = $rootnode->value("Level 1[$intLevel1Ctr].Link Target");
# Iterate Level 2. This is a replicant item within the Level 1 replicant
my $intLevel2Ctr = 0;
foreach my $level_2 (?){
# Iterate Level 3. This is a replicant item within the Level 3 replicant
my $intLevel3Ctr = 0;
foreach my $level_3 (?){
# Iterate Level 4. This is a replicant item within the Level 3 replicant
my $intLevel4Ctr = 0;
foreach my $level_4 (?){
$intLevel4Ctr++;
}
$intLevel3Ctr++;
}
$intLevel2Ctr++;
}
$intLevel1Ctr++;
}
I have done this before millions of times from within a TPL but it seems the code is lower level then when your doing this outside of templating.
sub getPageContext {
#LEVEL 1
# Start search
my $intLevel_1Ctr = 0;
foreach my $level_1(iwpt_dcr_list('this_dcr.Level 1')) {
$intLevel_1Ctr ++;
my $linkText = iwpt_dcr_value('level_1.Link Text');
my $strURL = iwpt_dcr_value('level_1.Link URL');
# if match then no children and set L1 context
if($strURL eq $strFilePath) {
$intL1Index = $intLevel_1Ctr;
}
#LEVEL 2
my $intLevel_2Ctr = 0;
foreach my $level_2(iwpt_dcr_list('level_1.Level 2')) {
$intLevel_2Ctr ++;
my $linkText = iwpt_dcr_value('level_2.Link Text');
my $strURL = iwpt_dcr_value('level_2.Link URL');
# if match then no children and set L1 and L2 context
if($strURL eq $strFilePath) {
$intL1Index = $intLevel_1Ctr;
$intL2Index = $intLevel_2Ctr;
}
#LEVEL 3
my $intLevel_3Ctr = 0;
foreach my $level_3(iwpt_dcr_list('level_2.Level 3')) {
$intLevel_3Ctr ++;
my $linkText = iwpt_dcr_value('level_3.Link Text');
my $strURL = iwpt_dcr_value('level_3.Link URL');
# if match then no children and set L1, L2 and L3 context
if($strURL eq $strFilePath) {
$intL1Index = $intLevel_1Ctr;
$intL2Index = $intLevel_2Ctr;
$intL3Index = $intLevel_3Ctr;
}
#LEVEL 4
my $intLevel_4Ctr = 0;
foreach my $level_4(iwpt_dcr_list('level_3.Level 4')) {
$intLevel_4Ctr ++;
my $linkText = iwpt_dcr_value('level_4.Link Text');
my $strURL = iwpt_dcr_value('level_4.Link URL');
# if match then no children and set L1, L2 and L4 context
if($strURL eq $strFilePath) {
$intL1Index = $intLevel_1Ctr;
$intL2Index = $intLevel_2Ctr;
$intL3Index = $intLevel_3Ctr;
$intL4Index = $intLevel_4Ctr;
}
}
}
}
}
}
Edited by Tim__D on 05/25/05 09:17 AM (server time).