如何根据这些数据生成 XML 文件?
$("#savequiz").click(function(){
var text = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><quiz>";
// save the general settings
text += "<title><![CDATA[" + $('input[name="title"]').val() + "]]></title>";
text += "<time><![CDATA[" + $('input[name="time"]').val() + "]]></time>";
text += "<singlechoice><![CDATA[" + $('input[name="singlechoice"]').val() + "]]></singlechoice>";
text += "<multiplechoice><![CDATA[" + $('input[name="multiplechoice"]').val() + "]]></multiplechoice>";
text += "<nextbutton><![CDATA[" + $('input[name="nextbutton"]').val() + "]]></nextbutton>";
text += "<prevbutton><![CDATA[" + $('input[name="prevbutton"]').val() + "]]></prevbutton>";
text += "<finishbutton><![CDATA[" + $('input[name="finishbutton"]').val() + "]]></finishbutton>";
text += "<startbutton><![CDATA[" + $('input[name="startbutton"]').val() + "]]></startbutton>";
text += "<reviewbutton><![CDATA[" + $('input[name="reviewbutton"]').val() + "]]></reviewbutton>";
text += "<resultscreentitle><![CDATA[" + $('input[name="resultscreentitle"]').val() + "]]></resultscreentitle>";
text += "<resultscreenresultline><![CDATA[" + $('input[name="resultscreenresultline"]').val() + "]]></resultscreenresultline>";
text += "<welcometext><![CDATA[" + $('textarea[name="welcometext"]').val() + "]]></welcometext>";
for(var i = 0; i < questions.length; i++) {
var q = questions[i];
var answers = q.getAnswers();
text += "<question><![CDATA[" + q.getQuestion() + "]]>";
for(var n = 0; n < answers.length; n++){
text += "<answer correct='" + answers[n].getCorrect() + "'>";
text += "<![CDATA[" + answers[n].getAnswer() + "]]></answer>";
};
text +="</question>";
};
text +="</quiz>";
// save to file:
$.ajax({
type: 'POST',
url: "savequiz.php",
dataType: 'json',
data: "filename=" + filename + ".xml" + "&quiz=" + text,
success: function (text) {
//console.log(text.errors);
//console.log(text.feedback);
if(text.feedback == "saved") respondChangedState(false);
}
});
PHP 文件看起来如何能够检索信息,然后将其保存到同一文件夹中的文件中?