This topic contains 1 reply, has 2 voices, and was last updated by Jeff Drumm 6 years, 9 months ago.
nested looping in XML
-
Hello,
I am trying to loop through an XMl message that has loops nested in other loops. I keep getting the incorrect number of results when I write it to the DB table. Here is what the message looks like
<includedPlanCategory>
<planIdentifier>45515VT095000600</planIdentifier>
<totalEnrollees>1</totalEnrollees>
<claimsIncluded>1</claimsIncluded>
<claimsExcluded>0</claimsExcluded>
<totalEnrolleesWRaEligibleclaims>1</totalEnrolleesWRaEligibleclaims>
– <includedBilltypeCategory>
<billTypeCode>111</billTypeCode>
<claimsIncluded>1</claimsIncluded>
<claimsExcluded>0</claimsExcluded>
</includedBilltypeCategory>
– <includedBilltypeCategory>
<billTypeCode>112</billTypeCode>
<claimsIncluded>1</claimsIncluded>
<claimsExcluded>1</claimsExcluded>
</includedBilltypeCategory>
– <includedServiceCodeCategory>
<serviceCode>V2499</serviceCode>
<claimsIncluded>1</claimsIncluded>
<claimsExcluded>0</claimsExcluded>
</includedServiceCodeCategory>
– <includedReasonCodeCategory>
<reasonCode />
<claimsExcluded>0</claimsExcluded>
</includedReasonCodeCategory>
– <includedMedicalClaimCategory>
<enrolleeIdentifier>Rtt03451I</enrolleeIdentifier>
<medicalClaimIdentifier>129855261</medicalClaimIdentifier>
<raEligibleIndicator>1</raEligibleIndicator>
<billTypeCode>111</billTypeCode>
<serviceCode>V2499</serviceCode>
<reasonCode />
</includedMedicalClaimCategory>
</includedPlanCategory>
– <includedPlanCategory>
<planIdentifier>45515VT095000700</planIdentifier>
<totalEnrollees>1</totalEnrollees>
<claimsIncluded>1</claimsIncluded>
<claimsExcluded>0</claimsExcluded>
<totalEnrolleesWRaEligibleclaims>1</totalEnrolleesWRaEligibleclaims>
– <includedBilltypeCategory>
<billTypeCode>111</billTypeCode>
<claimsIncluded>1</claimsIncluded>
<claimsExcluded>0</claimsExcluded>
</includedBilltypeCategory>
– <includedServiceCodeCategory>
<serviceCode>V2499</serviceCode>
<claimsIncluded>1</claimsIncluded>
<claimsExcluded>0</claimsExcluded>
</includedServiceCodeCategory>
– <includedReasonCodeCategory>
<reasonCode />
<claimsExcluded>0</claimsExcluded>
</includedReasonCodeCategory>
– <includedMedicalClaimCategory>
<enrolleeIdentifier>Rtt03451I</enrolleeIdentifier>
<medicalClaimIdentifier>129855261</medicalClaimIdentifier>
<raEligibleIndicator>1</raEligibleIndicator>
<billTypeCode>111</billTypeCode>
<serviceCode>V2499</serviceCode>
<reasonCode />
</includedMedicalClaimCategory>
</includedPlanCategory>The problem I am having is in the includedPlanTypeCategory, the includedBillTypeCategory is repeating 9 times and whould repeat 2 times for the first includedPlanTypeCategory and 1 time for the second planTypeCategory.
Code looks like this
for b=1, xDoc.riskAdjustmentClaimSelectionDetailReport.includedCalendarYearCategory:childCount(“includedPlanCategory”)
do
local ipc = xDoc.riskAdjustmentClaimSelectionDetailReport.includedCalendarYearCategory:child(“includedPlanCategory”,b)
local pi = ipc[“planIdentifier”]:text():nodeValue()
RACSD_Included_Plan_Category(ipc,cy)
for c=b, xDoc.riskAdjustmentClaimSelectionDetailReport.includedCalendarYearCategory.includedPlanCategory:childCount(“includedBilltypeCategory”) do
local ibt = xDoc.riskAdjustmentClaimSelectionDetailReport.includedCalendarYearCategory.includedPlanCategory:child(“includedBilltypeCategory”,c)RACSD_Included_Bill_Type(ibt,cy, pi)
end
endThanks for the Help
BradHi Brad,
Not sure why you’re using b as the loop start for the inner loop. Here’s a somewhat scrubbed version of your code that seems to get the correct iterations for the XML provided:
local ipy = xDoc.riskAdjustmentClaimSelectionDetailReport.includedCalendarYearCategory for b=1, ipy:childCount("includedPlanCategory") do local ipc = ipy:child("includedPlanCategory",b) local pi = ipc.planIdentifier[1]:S() RACSD_Included_Plan_Category(ipc,cy) for c=1, ipc:childCount("includedBilltypeCategory") do local ibt = ipc:child("includedBilltypeCategory",c) RACSD_Included_Bill_Type(ibt,cy, pi) end end
For each includedPlanCategory parent, you should be starting from 1 when looping through the includedBilltypeCategory children.
Jeff Drumm ◊ VP and COO ◊ HICG, LLC. ◊ http://www.hicgrp.com
You must be logged in to reply to this topic.