New to forum, fairly new to ColdFusion. I am trying to parse an XML file and get a list of the fields in the following XML file. I would like all the Course Schedule/Class Event/ClassEventID items to list under that parent all the ClassEvent children.
I am attaching the XML file (CourseInformation_sample.xml) and transcribing the ColdFusion code I am using. I also transcribed the rendered ColdFusion file The problem is I get only the first ClassEventID (and concurrent children) and am not sure how to nest a loop (?) so that I get all the ClassEventID (and concurrent children) listed under the corresponding parent element.
Code for CourseInformation_sample_read.cfm
<CFSET CourseInformation_Short = ExpandPath("CourseInformation_sample.xml")>
<cffile
action="read"
file="#CourseInformation_Short#"
variable="DisVarXMLFile">
<cfset WorkingXMLDoc = xmlParse(DisVarXMLFile)>
<cfset CourseNodes = xmlSearch(WorkingXMLDoc,'/CourseInformation/Courses/Course')>
<cfoutput>
<cfloop from="1" to="#arraylen(CourseNodes)#" index="i">
<!--- The array contents need to parsed so you can easily get at the child nodes children and attributes. --->
<cfset CourseXML = xmlparse(CourseNodes[i])>
<cfset currentrow = i> [#currentrow#]<br>
<b>Course Title:</b> #CourseXML.Course.CourseTitle.xmltext#<br>
<b>Course Number:</b> #CourseXML.Course.CourseNumber.xmlText#
<br><br>
[code]<b>Class Event ID:</b> #CourseXML.Course.CourseSchedule.ClassEvent.ClassEventID.xmlText#<br>
<b>Start Date:</b> #CourseXML.Course.CourseSchedule.ClassEvent.StartDate.xmlText#<br>
<b>End Date:</b> #CourseXML.Course.CourseSchedule.ClassEvent.EndDate.xmlText#<br>
<b>Location:</b> #CourseXML.Course.CourseSchedule.ClassEvent.Location.xmlText#<br>
<hr>
</cfloop>
<br>
</cfoutput>
Following is how CourseInformation_sample_read.cfm renders - note that only the first Class Event ID is listed. I have tried several different nested loops but I can't seem to get anything other than only one Class Event ID to list or else a separate list of ALL (aggregated) Class Event IDs in one big list. I have looked at more than 20 article on the Web, cannot get anything to work properly. I might be missing the obvious.
[1]
Course Title: Preparing for MCTS Windows Server 2008 Active Directory Exam 70-640
Course Number: 1110
Class Event ID: 12AE61US
Start Date: 10/31/2012
End Date: 11/02/2012
Location: Washington, DC (Reston, VA)
[2]
Course Title: Achieving ITIL Foundation Certification
Course Number: 1197
Class Event ID: 129A05US
Start Date: 09/19/2012
End Date: 09/21/2012
Location: Washington, DC (Rockville, MD)
[3]
Course Title: Cloud Computing Technologies: A Comprehensive Hands-On Introduction
Course Number: 1200
Class Event ID: 129A00CN
Start Date: 09/19/2012
End Date: 09/21/2012
Location: Ottawa
Thank you in advance.
Attached File(s)
-
CourseInformation_sample.xml (2.01K)
Number of downloads: 70
This post has been edited by Craig328: 25 September 2012 - 10:53 AM

New Topic/Question
Reply



MultiQuote





|