Ejemplo n.º 1
0
        public static List <string> CreateXML(string filename, List <Question> questions)
        {
            int           questionsSkipped = 0;
            List <string> result           = new List <string>();

            result.Add("Processing " + questions.Count.ToString() + " unsupported question types to XML....");

            // make new XML doc
            XmlDocument xmlDoc = new XmlDocument();

            XmlNode quizNode = xmlDoc.CreateElement("quiz");

            xmlDoc.AppendChild(quizNode);

            // add nodes
            for (int i = 0; i < questions.Count; i++)
            {
                XmlNode qNode = questions[i].xmlNode;
                if (qNode != null)
                {
                    XmlNode question = quizNode.OwnerDocument.ImportNode(qNode, true);
                    quizNode.AppendChild(question);
                }
            }



            // write to file
            JwXML.WriteToFile(xmlDoc, filename);

            result.Add("\tOK. " + questionsSkipped.ToString() + " questions skipped (no XML data)");

            // return result
            return(result);
        }
Ejemplo n.º 2
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);
        }