/*/ <summary> * /// This property is inherited from an abstract property * /// but does not make sense for this class - we therefore throw an error here. * /// </summary> * public override string TypeKey * { * get * { * throw new NotImplementedException(); * } * } */ #endregion properties #region methods /// <summary> /// Persist an Xml document and its content into an XML formated string. /// </summary> /// <param name="root"></param> /// <param name="docRoot"></param> /// <returns></returns> public static string Write(PageViewModelBase root, IEnumerable <ShapeViewModelBase> docRoot) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; // 2 spaces as indentation settings.NewLineOnAttributes = true; try { using (var sw = new StringWriter()) { using (XmlWriter writer = XmlWriter.Create(sw, settings)) { root.SaveDocument(writer, docRoot); } return(sw.ToString()); } } catch (Exception e) { throw new Exception("An exception occured when writing XML.", e); } }
/// <summary> /// Persist an Xml document and its content into /// an XML formated text file. /// </summary> /// <param name="root"></param> /// <param name="docRoot"></param> /// <returns></returns> public static bool Write(string filePathName, PageViewModelBase root, IEnumerable <ShapeViewModelBase> docRoot) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; // 2 spaces as indentation settings.NewLineOnAttributes = true; try { using (XmlWriter writer = XmlWriter.Create(filePathName, settings)) { root.SaveDocument(writer, docRoot); } return(true); } catch (Exception e) { throw new Exception("An error occured when writing XML.", e); } }