Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing XML

Status
Not open for further replies.

redoakhg

Programmer
Nov 30, 2006
38
0
0
US
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
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 :
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top