Last active
April 4, 2018 09:13
-
-
Save asquigglytwist/23c130a65a72112f14c89b6d3cbae6a3 to your computer and use it in GitHub Desktop.
Save info to an XML doc.
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
var xDoc = new XmlDocument(); | |
var declarationNode = xDoc.CreateXmlDeclaration("1.0", "", ""); | |
xDoc.AppendChild(declarationNode); | |
var comment = xDoc.CreateComment(string.Format("This file contains information about {0} - {1}", BookName, BookName)); | |
xDoc.AppendChild(comment); | |
var docRoot = xDoc.CreateElement("Books"); | |
XmlNode ndBookISBN = xDoc.CreateElement("BookISBNCode"), | |
ndBookName = xDoc.CreateElement("BookName"), | |
ndAuthorName = xDoc.CreateElement("AuthorName"), | |
ndReleaseDate = xDoc.CreateElement("ReleaseDate"); | |
ndBookISBN.InnerText = BookISBNCode; | |
ndBookName.InnerText = BookName; | |
ndAuthorName.InnerText = AuthorName; | |
ndReleaseDate.InnerText = ReleaseDate; | |
docRoot.AppendChild(ndBookISBN); | |
docRoot.AppendChild(ndBookName); | |
docRoot.AppendChild(ndAuthorName); | |
docRoot.AppendChild(ndReleaseDate); | |
xDoc.AppendChild(docRoot); | |
try | |
{ | |
AppGlobal.CreateDirectory(dirPath); | |
xDoc.Save(XMLFilePath); | |
return true; | |
} | |
catch (Exception e) | |
{ | |
throw new Exception(string.Format("Unable to save info on {0} to file.{1}Message:{2}.", BookName, Environment.NewLine, e.Message), e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment