Skip to content

Instantly share code, notes, and snippets.

@zygisx
Created March 7, 2012 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zygisx/1995109 to your computer and use it in GitHub Desktop.
Save zygisx/1995109 to your computer and use it in GitHub Desktop.
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