I am pulling my hair out. This is my first stab at parsing XML and getting the values into a MS SQL database.
MY CODE
Attached you will find an image of the XML structure. If not you can see it here
<b>The error I receive is:<b/>
The index of a child element is out of range.
There are only 173 children under this node.
Index 174 is out of the allowed range [1-173].
The error occurred in C:\inetpub\ line 24
22 : <cfloop from="1" to="#adverts#" index="i">
23 : <cfoutput>
24 : <cfset medianodes = ArrayLen(XMLFile.ProcessVehicleRemarketing.ProcessVehicleRemarketingDataArea.VehicleRemarketing.VehicleRemarketingBoatLineItem.ImageAttachmentExtended.XmlChildren) />
25 :
26 :
MY CODE
Code:
<cffile action="Read" file="C:\inetpub\[URL unfurl="true"]wwwroot\am\xml\thexml.xml"[/URL] variable="readText">
<!--- Create a new ColdFusion XML document object --->
<cfxml variable="XMLFile">
<cfoutput>#readText#</cfoutput>
</cfxml>
<!---Delete all existing records--->
<cfquery name="deletemedia" datasource="#datasource#">
DELETE FROM phototbl
</cfquery>
<cfset adverts = ArrayLen(XMLFile.ProcessVehicleRemarketing.ProcessVehicleRemarketingDataArea.XmlChildren) />
<cfloop from="1" to="#adverts#" index="i">
<cfset medianodes = ArrayLen(XMLFile.ProcessVehicleRemarketing.ProcessVehicleRemarketingDataArea.VehicleRemarketing[i].VehicleRemarketingBoatLineItem.ImageAttachmentExtended.XmlChildren) />
<cfif medianodes GT 0>
<!---<cfdump var="#medianodes#">--->
<cfloop from="1" to="#medianodes#" index="j">
<cftry>
<cfoutput>
<cfquery name="inertmedia" datasource="#datasource#">
Insert Into phototbl(pho_lrg,lis_id,isprimary)
Values( '#XMLFile.ProcessVehicleRemarketing.ProcessVehicleRemarketingDataArea.VehicleRemarketing[i].VehicleRemarketingBoatLineItem.ImageAttachmentExtended[j].URI#',
'8102',
'1'
)
</cfquery>
</cfoutput>
<cfcatch type="any">
<cfoutput>#cfcatch.detail#</cfoutput>
</cfcatch>
</cftry>
</cfloop>
</cfif>
</cfloop>
Attached you will find an image of the XML structure. If not you can see it here
<b>The error I receive is:<b/>
The index of a child element is out of range.
There are only 173 children under this node.
Index 174 is out of the allowed range [1-173].
The error occurred in C:\inetpub\ line 24
22 : <cfloop from="1" to="#adverts#" index="i">
23 : <cfoutput>
24 : <cfset medianodes = ArrayLen(XMLFile.ProcessVehicleRemarketing.ProcessVehicleRemarketingDataArea.VehicleRemarketing.VehicleRemarketingBoatLineItem.ImageAttachmentExtended.XmlChildren) />
25 :
26 :