public static Question GetQuestionUnknown(XmlNode myNode) { Question q = new Question(); q.name = JwString.CleanQuestionName(JwXML.GetNodeValue(myNode, "name/text")); q.text = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text")); q.type = JwXML.GetNodeAttribute(myNode, "type"); q.xmlNode = myNode; // feedback q.generalfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "generalfeedback/text")); q.correctfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "correctfeedback/text")); q.incorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "incorrectfeedback/text")); q.partiallycorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "partiallycorrectfeedback/text")); XmlNodeList answers = JwXML.GetNodes(myNode, "answer"); foreach (XmlNode answer in answers) { string optionText = JwString.Clean(JwXML.GetNodeValue(answer, "text")); string optionFeedback = JwString.Clean(JwXML.GetNodeValue(answer, "feedback")); float optionGrade = float.Parse(JwXML.GetNodeAttribute(answer, "fraction", "0")); q.AddOption(optionText, optionFeedback, optionGrade); } return(q); }
public static List <Question> ReadFile(string xmlFile) { List <Question> qList = new List <Question>(); XmlDocument doc = JwXML.Load(xmlFile); string currentCategory = ""; XmlNodeList questionNodes = JwXML.GetNodes(doc, "/quiz/question"); for (int i = 0; i < questionNodes.Count; i++) { string type = JwXML.GetNodeAttribute(questionNodes[i], "type"); if (type == "category") { currentCategory = JwString.CleanCategory(questionNodes[i].InnerText); } else if (type == "multichoice" || type == "multichoiceset" || type == "truefalse") { Question q = Moodle.GetQuestionMultichoice(questionNodes[i]); q.category = currentCategory; qList.Add(q); } else if (type == "cloze") { Question q = Moodle.GetQuestionCloze(questionNodes[i]); q.category = currentCategory; qList.Add(q); } else if (type == "ddwtos") { Question q = Moodle.GetQuestionDragDropText(questionNodes[i]); q.category = currentCategory; qList.Add(q); } else if (type == "hotspot") { Question q = Moodle.GetQuestionHotspot(questionNodes[i]); q.category = currentCategory; qList.Add(q); } else { // default option - don't know what to do with question Question q = Moodle.GetQuestionUnknown(questionNodes[i]); q.category = currentCategory; qList.Add(q); } } return(qList); }
public static Question GetQuestionHotspot(XmlNode myNode) { Question q = new Question(); q.name = JwXML.GetNodeValue(myNode, "name/text"); q.text = JwXML.GetNodeValue(myNode, "questiontext/text"); q.type = JwXML.GetNodeAttribute(myNode, "type"); // feedback q.generalfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "generalfeedback/text")); q.correctfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "correctfeedback/text")); q.incorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "incorrectfeedback/text")); q.partiallycorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "partiallycorrectfeedback/text")); // get data string data = "{"; // compile data from XML nodes data += "areashape:" + JwXML.GetNodeValue(myNode, "areashape") + ","; data += "rectangleleft:" + JwXML.GetNodeValue(myNode, "rectangleleft") + ","; data += "rectangletop:" + JwXML.GetNodeValue(myNode, "rectangletop") + ","; data += "rectangleright:" + JwXML.GetNodeValue(myNode, "rectangleright") + ","; data += "rectanglebottom:" + JwXML.GetNodeValue(myNode, "rectanglebottom") + ","; data += "imagewidth:" + JwXML.GetNodeValue(myNode, "imagewidth") + ","; data += "imageheight:" + JwXML.GetNodeValue(myNode, "imageheight") + ","; data += "areacorrect:" + JwXML.GetNodeValue(myNode, "areacorrect"); data += "}"; q.data = data; // images? XmlNodeList imageNodes = JwXML.GetNodes(myNode, "file"); // "questiontext/file"); foreach (XmlNode imageNode in imageNodes) { string imageName = JwXML.GetNodeAttribute(imageNode, "name"); string imageData = ""; if (imageNode != null) { imageData = imageNode.InnerText; } if (imageName != String.Empty) { q.AddImage(imageName, imageData); } } return(q); }
public static Question GetQuestionMultichoice(XmlNode myNode) { Question q = new Question(); q.name = JwString.CleanQuestionName(JwXML.GetNodeValue(myNode, "name/text")); q.text = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text")); q.type = JwXML.GetNodeAttribute(myNode, "type"); q.generalfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "generalfeedback/text")); q.correctfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "correctfeedback/text")); q.incorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "incorrectfeedback/text")); q.partiallycorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "partiallycorrectfeedback/text")); // images? XmlNodeList imageNodes = JwXML.GetNodes(myNode, "questiontext/file"); foreach (XmlNode imageNode in imageNodes) { string imageName = JwXML.GetNodeAttribute(imageNode, "name"); string imageData = ""; if (imageNode != null) { imageData = imageNode.InnerText; } if (imageName != String.Empty) { q.AddImage(imageName, imageData); } } XmlNodeList answers = JwXML.GetNodes(myNode, "answer"); foreach (XmlNode answer in answers) { string optionText = JwString.Clean(JwXML.GetNodeValue(answer, "text")); string optionFeedback = JwString.Clean(JwXML.GetNodeValue(answer, "feedback")); float optionGrade = float.Parse(JwXML.GetNodeAttribute(answer, "fraction", "0")); q.AddOption(optionText, optionFeedback, optionGrade); } return(q); }
public static Question GetQuestionDragDropText(XmlNode myNode) { Question q = new Question(); q.name = JwString.CleanQuestionName(JwXML.GetNodeValue(myNode, "name/text")); q.type = JwXML.GetNodeAttribute(myNode, "type"); string qData = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text")); qData = qData.Replace("<![CDATA[", ""); qData = qData.Replace("]]>", ""); // get question text string pattern = @"[[\d+]]"; string qText = Regex.Replace(qData, pattern, " ________ "); q.text = qText.Trim(); q.xmlNode = myNode; return(q); }
public static Question GetQuestionClozeType2(XmlNode myNode) { Question q = new Question(); q.name = JwString.CleanQuestionName(JwXML.GetNodeValue(myNode, "name/text")); q.type = JwXML.GetNodeAttribute(myNode, "type"); // feedback q.generalfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "generalfeedback/text")); q.correctfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "correctfeedback/text")); q.incorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "incorrectfeedback/text")); q.partiallycorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "partiallycorrectfeedback/text")); string qData = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text")); qData = qData.Replace("<![CDATA[", ""); qData = qData.Replace("]]>", ""); // get question text string pattern = @"{:MULTICHOICE(.*?)}"; string qText = Regex.Replace(qData, pattern, " ________ "); q.text = qText.Trim(); // images? XmlNodeList imageNodes = JwXML.GetNodes(myNode, "questiontext/file"); foreach (XmlNode imageNode in imageNodes) { string imageName = JwXML.GetNodeAttribute(imageNode, "name"); string imageData = ""; if (imageNode != null) { imageData = imageNode.InnerText; } if (imageName != String.Empty) { q.AddImage(imageName, imageData); } } // get answer options MatchCollection blanks = Regex.Matches(qData, pattern); if (blanks.Count > 1) { q.type = "UNSUPPORTED: " + q.type; q.xmlNode = myNode; } for (int i = 0; i < blanks.Count; i++) { // get correct options string pattern2 = @"=([^~]+)[~}]"; MatchCollection matches2 = Regex.Matches(blanks[i].Value, pattern2); for (int j = 0; j < matches2.Count; j++) { string optionText = matches2[j].Groups[1].ToString().Trim(); string optionFeedback = ""; float optionGrade = 1.0f; q.AddOption(optionText, optionFeedback, optionGrade); } // get incorrect options string pattern3 = @"%-?\d*%([^~}]+)"; MatchCollection matches3 = Regex.Matches(blanks[i].Value, pattern3); for (int j = 0; j < matches3.Count; j++) { string optionText = matches3[j].Groups[1].ToString().Trim(); string optionFeedback = ""; float optionGrade = 0.0f; q.AddOption(optionText, optionFeedback, optionGrade); } } return(q); }
public static string GetQuestionType(XmlNode myNode, string defaultValue = "") { return(JwXML.GetNodeAttribute(myNode, "type", defaultValue)); }
public static List <Question> ReadFile(string xmlFile) { List <Question> qList = new List <Question>(); XmlDocument doc = JwXML.Load(xmlFile); XmlNodeList itemNodes = JwXML.GetNodes(doc, "/questestinterop/item"); for (int i = 0; i < itemNodes.Count; i++) { Question q = new Question(); q.name = JwXML.GetNodeAttribute(itemNodes[i], "ident"); //XmlNodeList children = itemNodes[i].ChildNodes; // get item data XmlNode metaData = JwXML.GetSingleNode(itemNodes[i], "itemmetadata"); q.type = JwXML.GetNodeValue(metaData, "qmd_itemtype"); q.category = JwXML.GetNodeValue(metaData, "qmd_topic"); // get question text q.text = JwXML.GetNodeValue(itemNodes[i], "presentation/material/mattext"); // get options XmlNodeList options = JwXML.GetNodes(itemNodes[i], "presentation/response_lid/render_choice/response_label"); for (int index = 0; index < options.Count; index++) { string optionText = JwString.Clean(options[index].InnerText); q.AddOption(optionText, "", 0); } // find correct answer XmlNodeList responses = JwXML.GetNodes(itemNodes[i], "resprocessing/respcondition"); for (int index = 0; index < responses.Count; index++) { string setVar = JwXML.GetNodeValue(responses[index], "setvar", "0"); if (index < q.options.Count) { q.options[index].grade = float.Parse(setVar) * 100; } } // get feedback XmlNodeList feedbacks = JwXML.GetNodes(itemNodes[i], "itemfeedback"); for (int index = 0; index < feedbacks.Count; index++) { string feedback = JwXML.GetNodeValue(feedbacks[index], "material/mattext"); if (index < q.options.Count) { q.options[index].feedback = feedback; } } // add question to qList qList.Add(q); } return(qList); }