473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Sorting XML data ??

I have the following XML file:

<?xml version="1.0" encoding="utf-8"?>
<class>
<sdate>9/10/07</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
<sdate>10/22/07</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
<sdate>11/26/07</sdate>
<special>3</special>
<inst>Max Callao</inst>
<sdate>1/28/08</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
<sdate>3/10/08</sdate>
<special>3</special>
<inst>Max Callao</inst>
<sdate>4/21/08</sdate>
<special>1,2</special>
<inst>Max Callao</inst>
</class>

And am displaying it with the following Coldfusion code:

<cffile action="read" file="C:\Inetpub\wwwroot\SalleBoise\sb1.xml"
variable="xmldoc">
<cfset mydoc = XmlParse(xmldoc)>

<cfset mydoc_stuff = XmlSearch(mydoc, "/class/sdate")>
<cfset cl_inst= XmlSearch(mydoc, "/class/inst")>
<cfset cl_spec=xmlSearch(mydoc, "/class/special")>

<cfset CurrDate=dateformat(now(),"mmmm d,yyyy")>
<!--- Starts off the inital item count --->
<cfset icount=1>

<div align="left" style="margin:0 auto;">
<cfloop index="mydoc_item" from="1" to=#ArrayLen(mydoc_stuff)#>
<cfset mydoc_data = mydoc_stuff[mydoc_item].XmlText>
<cfset mydoc_inst= cl_inst[mydoc_item].XmlText>
<cfset mydoc_spec=cl_spec[mydoc_item].XmlText>

<!--- Find the number of days between the start of the session and the
current date --->
<cfset temp=datediff("d",mydoc_data,CurrDate)>
<!--- Send end date for classes, calculated by adding 23 days to start
of beginning of class --->
<cfset temp2=dateformat(dateadd("d",23,mydoc_data),"m/d/yy")>
<!--- Check to see if date of classes are more than 7 months out, or
are more than 5 days (based on class ending date) in the past, if so,
don't display --->
<cfif (datediff("m",CurrDate,mydoc_data) gte 7) or
(datediff("d",temp2,CurrDate) gte 5)>
<cfelse>
<!--- If class date is more than 23 days old, mark as 'not available'
--->
<cfif temp gt 23>
<img src="images/small_no_class.gif" style="padding-right:5px; margin-
left:25px;" alt="Session ended" /><cfoutput>Session #icount#: <span
class="fake_strikethrough">#mydoc_data# -- #temp2#</span><br />
<div align="left" style="font:Arial, Helvetica, sans-serif; font-size:
10px; float:left; padding-left:62px;">Instructor: #mydoc_inst#</
div><br clear="left">
<div style="padding-left:62px; float:left; font-size:10px;">Class
type: <cfloop list="#mydoc_spec#" delimiters="," index="i">
<cfswitch expression="#i#">
<cfcase value="1">
Beginner,
</cfcase>
<cfcase value="2">
Intermediate
</cfcase>
<cfcase value="3">
Workshop session
</cfcase>
</cfswitch>
</cfloop>
</div><br clear="left">
<!--- <cfif len(mydoc_spec) gte 1><div style="padding-left:10px;
float:left; font-size:9px;"><strong>Workshop session</strong></div><br
clear="left"></cfif--->
</cfoutput>
<!--- If class more than 2 days old AND less than the ending date of
23 days, mark as 'in session' --->
<cfelseif (datediff("d",mydoc_data,CurrDate) gt 2) and
(datediff("d",mydoc_data,CurrDate) lte 23)>
<img src="images/small_in_session_class.gif" style="padding-right:5px;
margin-left:25px;" alt="In session" /><cfoutput>Session #icount#:
#mydoc_data# -- #temp2#<br />
<div align="left" style="font:Arial, Helvetica, sans-serif; font-size:
10px; float:left; padding-left:62px;">Instructor: #mydoc_inst#</
div><br clear="left">
<div style="padding-left:62px; float:left; font-size:10px;">Class
type: <cfloop list="#mydoc_spec#" delimiters="," index="i">
<cfswitch expression="#i#">
<cfcase value="1">
Beginner,
</cfcase>
<cfcase value="2">
Intermediate
</cfcase>
<cfcase value="3">
Workshop session
</cfcase>
</cfswitch>
</cfloop>
</div><br clear="left">
</cfoutput>
<cfelse>
<!--- Otherwise mark the class as available to sign up for --->
<cfif datediff("d",CurrDate, mydoc_data) lte 30>
<!--- Display register icon if class is 30 days or less before start
of class --->
<div class="reg_img" style="float:right;"><a href="https://
www.memberst.com/Programs/Sessions.aspx?id=C4B5D9EB-55B1-41EB-99AE-2251ECEAD36C"
target="_blank"><cfoutput>
<img src="images/small_online_register.gif" alt="Register for
#mydoc_data# class" name="register" width="15" height="15" border="0"
style="padding-left:5px;" title="Register for #mydoc_data# class"/></
cfoutput></a></div>
</cfif>
<img src="images/small_yes_class.gif" style="padding-right:5px; margin-
left:25px;" alt="Available" /><cfoutput>Session #icount#:
#mydoc_data# -- #temp2#<br />
<div align="left" style="font:Arial, Helvetica, sans-serif; font-size:
10px; float:left; padding-left:62px;">Instructor: #mydoc_inst#</
div><br clear="left">
<div style="padding-left:62px; float:left; font-size:10px;">Class
type: <cfloop list="#mydoc_spec#" delimiters="," index="i">
<cfswitch expression="#i#">
<cfcase value="1">
Beginner,
</cfcase>
<cfcase value="2">
Intermediate
</cfcase>
<cfcase value="3">
Workshop session
</cfcase>
</cfswitch>

I would like to find a way I can add an additional date at the bottom
of the xml file, and still have the dates sorted correctly. I was
told about XSLT, but since I need the Coldfusion part of the code to
remain, I'm not sure how I can 'sort' the XML file before its looped
over by the Coldfusion.

Does anyone have any suggestions?

Thanks!

Jun 7 '07 #1
0 2039

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
6
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.