コード例 #1
0
ファイル: PageViewModelBase.cs プロジェクト: rasyidf/Edi
        /*/ <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);
            }
        }
コード例 #2
0
ファイル: PageViewModelBase.cs プロジェクト: denis554/Edi-1
        /// <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);
            }
        }