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); }
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); }