Created
March 7, 2012 18:56
-
-
Save zygisx/1995109 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void AppendQuestions(string question, | |
string answer, string case1, string case2, string difficulty) | |
{ | |
try { | |
XmlDocument XmlDoc = new XmlDocument(); | |
XmlDoc.Load(XML_FILE_PATH); | |
XmlElement newElem = XmlDoc.CreateElement("task"); | |
XmlAttribute difficultyAttribute = XmlDoc.CreateAttribute("stage"); | |
difficultyAttribute.Value = difficulty; | |
newElem.Attributes.Append(difficultyAttribute); | |
newElem.InnerXml = "<question></question><answer></answer><case1></case1><case2></case2>"; | |
//XmlText txtNode = XmlDoc.CreateTextNode("A BRIEF HISTORY OF TIME"); | |
//newElem.FirstChild.AppendChild(txtNode); | |
//newElem.AppendChild(doc.CreateWhitespace("\r\n")); // Linefeed | |
newElem["question"].InnerText = question; | |
newElem["answer"].InnerText = answer; | |
newElem["case1"].InnerText = case1; | |
newElem["case2"].InnerText = case2; | |
XmlDoc.DocumentElement.LastChild.AppendChild(newElem); | |
XmlDoc.Save(XML_FILE_PATH); | |
} | |
catch (XmlException xmlEx) // Handle the Xml exceptions here. | |
{ | |
Console.WriteLine("{0}", xmlEx.Message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment