Most XML data can be directly assigned to simple objects like strings and numbers, but when you have a more complex data type like a Date, you need to do a little parsing first.

Consider the following XML:

var response : XML =
        <status date="2011-07-07">200</status>

I’ve covered how to get the data in the ‘status’ node before, but to get the data in the ‘date’ attribute and assign it to a Date object, you’d do the following in your code:

var dateString : String = response.status.@date;
var date : Date = DateFormatter.parseDateString (dateString);

Note that this will only work if the dateString is in an appropriate format, like “YYYY-MM-DD” or “YYYY-MM-DD HH:MM:SS”.