Example #1
0
        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);
        }
Example #2
0
        public static string GetVar(string name, string defaultValue = "")
        {
            XmlDocument doc       = JwXML.Load(cfgFile);
            XmlNodeList variables = JwXML.GetNodes(doc, "config/variable");

            foreach (XmlNode variable in variables)
            {
                string varName = JwXML.GetNodeValue(variable, "name");

                if (varName == name)
                {
                    return(JwXML.GetNodeValue(variable, "value", defaultValue));
                }
            }

            return(defaultValue);
        }
Example #3
0
        public static void SetVar(string name, string value)
        {
            CheckCfgFileExists();

            XmlDocument doc        = JwXML.Load(cfgFile);
            XmlNodeList variables  = JwXML.GetNodes(doc, "config/variable");
            Boolean     addNewNode = true;

            foreach (XmlNode variable in variables)
            {
                string varName = JwXML.GetNodeValue(variable, "name");

                if (varName == name)
                {
                    addNewNode = false;
                    JwXML.GetSingleNode(variable, "value").InnerText = value;
                }
            }

            // add new variable node?
            if (addNewNode)
            {
                XmlNode    config      = JwXML.GetSingleNode(doc, "config");
                XmlElement newVariable = doc.CreateElement("variable");
                XmlElement newName     = doc.CreateElement("name");
                newName.InnerText = name;
                newVariable.AppendChild(newName);
                XmlElement newValue = doc.CreateElement("value");
                newValue.InnerText = value;
                newVariable.AppendChild(newValue);
                config.AppendChild(newVariable);
            }

            //write back to file
            JwXML.WriteToFile(doc, cfgFile);
        }
Example #4
0
        public static XmlNodeList GetQuestionNodes(string sourceFile)
        {
            XmlDocument doc = JwXML.Load(sourceFile);

            return(doc.SelectNodes("/quiz/question"));
        }
Example #5
0
        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);
        }