I'm receiving an xml file that has a child called modified and it represents a date value in the form of a string -- Nov 14, 2008 -- and in my app, I have items associated with each object and I'm trying to sort them by the date modified field.
So what's the problem, right?
Well, obviously Sep 14, 2008 is before Nov 14, 2008, but when doing a sort process, ActionScript will come back with Nov coming before Sep, because N comes before S in any sort.
So I figured that I would convert the string to a number and then later specify that this is a numeric sort.
Here's the code that traverses through the XML and changes the string to numbers:
No problem, right? This definitely works, but that is not where my issue lies.
How do I re-insert the converted values in the exact same place as where it was located when I received the xml?
Or do I have to grab every object and reassemble it?
I'm hoping there is an easier way and, as usual, your help is appreciated and thanx n advance
So what's the problem, right?
Well, obviously Sep 14, 2008 is before Nov 14, 2008, but when doing a sort process, ActionScript will come back with Nov coming before Sep, because N comes before S in any sort.
So I figured that I would convert the string to a number and then later specify that this is a numeric sort.
Here's the code that traverses through the XML and changes the string to numbers:
Code:
public function createDate(s:String):String
{
var retStr:String = '';
var str2xml:XML = new XML(s);
var xml2list:XMLList = new XMLList(str2xml);
var list2col:XMLListCollection = new XMLListCollection(xml2list);
var mods:XMLList = list2col.children().child("modified");
var mod:String = list2col.children().child("modified").text();
for each(var h:XML in mods)
{
var xml2str:String = h;
trace("list2col"+list2col.children().child("modified").text());
switch(xml2str.substr(0,4))
{
case "Jan ":
xml2str=xml2str.replace("Jan ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Feb ":
xml2str=xml2str.replace("Feb ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Mar ":
xml2str=xml2str.replace("Mar ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Apr ":
xml2str=xml2str.replace("Apr ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "May ":
xml2str=xml2str.replace("May ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Jun ":
xml2str=xml2str.replace("Jun ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Jul ":
xml2str=xml2str.replace("Jul ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Aug ":
xml2str=xml2str.replace("Aug ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Sep ":
xml2str=xml2str.replace("Sep ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Oct ":
xml2str=xml2str.replace("Oct ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Nov ":
xml2str=xml2str.replace("Nov ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
case "Dec ":
xml2str=xml2str.replace("Dec ","01");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.replace(",","");
xml2str=xml2str.replace(" ","");
xml2str=xml2str.substr(0,8);
retStr = xml2str;
break;
default:
// do nothing
}
trace("retStr"+retStr);
}
return retStr;
}
How do I re-insert the converted values in the exact same place as where it was located when I received the xml?
Or do I have to grab every object and reassemble it?
I'm hoping there is an easier way and, as usual, your help is appreciated and thanx n advance
Comment