Пример #1
0
        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);
        }
Пример #2
0
        public static string GetQuestionDescriptionNOTUSED(XmlNode myNode)
        {
            string name         = JwXML.GetNodeValue(myNode, "name/text");
            string questionText = JwXML.GetNodeValue(myNode, "questiontext/text");

            string qData = "NAME: " + name + Environment.NewLine;

            qData += questionText;
            return(qData);
        }
Пример #3
0
        public static string GetQuestionShortAnswerNOTUSED(XmlNode myNode)
        {
            string name         = JwXML.GetNodeValue(myNode, "name/text");
            string questionText = JwXML.GetNodeValue(myNode, "questiontext/text");
            string answer       = JwXML.GetNodeValue(myNode, "answer/text");

            string qData = "NAME: " + name + Environment.NewLine;

            qData += "QUESTION: " + questionText + Environment.NewLine;
            qData += "ANSWER: " + answer + Environment.NewLine;

            return(qData);
        }
Пример #4
0
        public static Question GetQuestionCloze(XmlNode myNode)
        {
            string qData = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text"));

            if (qData.Contains("{:MULTICHOICE"))
            {
                return(GetQuestionClozeType2(myNode));
            }
            else
            {
                return(GetQuestionClozeType1(myNode));
            }
        }
Пример #5
0
        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);
        }
Пример #6
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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        public static string GetQuestionMatchingNOTUSED(XmlNode myNode)
        {
            string name         = JwXML.GetNodeValue(myNode, "name/text");
            string questionText = JwXML.GetNodeValue(myNode, "questiontext/text");

            string qData = "NAME: " + name + Environment.NewLine;

            qData += "QUESTION: " + questionText + Environment.NewLine;

            XmlNodeList subquestions = JwXML.GetNodes(myNode, "subquestion");

            foreach (XmlNode sub in subquestions)
            {
                string sText   = JwXML.GetNodeValue(sub, "text");
                string sAnswer = JwXML.GetNodeValue(sub, "answer/text");
                if (sText.Length > 0)
                {
                    qData += "OPTION: " + sText + Environment.NewLine;
                }
                qData += "    --> " + sAnswer + Environment.NewLine;
            }

            return(qData);
        }
Пример #10
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);
        }
Пример #11
0
        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);
        }
Пример #12
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);
        }