XML 将使数据模型对您的目标直观。
<?xml version="1.0" encoding="UTF-8"?>
<questions>
<question day="1"><![CDATA[ <b>Question 1</b>: Lorem ipsum dolor sit amet. ]]></question>
<question day="2"><![CDATA[ <b>Question 2</b>: Consectetur adipiscing elit. ]]></question>
<question day="3"><![CDATA[ <b>Question 3</b>: Duis semper risus nec nisi elementum. ]]></question>
</questions>
在 ActionScript 中,要获取一年中的当前日期,可以这样实现:
public static function getDayOfTheYear(d:Date):uint {
var firstDay:Date = new Date(d.getFullYear(), 0, 1);
return (d.getTime() - firstDay.getTime()) / 86400000;
}
加载 XML 后,您可以使用 e4x 获取当前问题节点:
var now:Date = new Date();
var day:uint = getDayOfTheYear(now);
/* Assuming you loaded XML to a variable: var xml:XML */
var question:XMLList = xml.question.(@day == day);
trace(question.valueOf());