public static void SaveXmlFile(System.IO.TextWriter writer, DomDocument document) { if (writer == null) { throw new ArgumentNullException("writer"); } if (document == null) { throw new ArgumentNullException("document"); } XmlSerializer ser = GetDocumentXmlSerializer(document.GetType()); //document._xmlSerializing = true; //document.ContentStyles.UpdateStyleIndex(); document.EditorVersion = DomDocument.CurrentEditorVersion; document.DeleteUselessStyle(); document._ElementsForSerialize = null; document._Deserializing = false; document.ContentStyles.Styles.UpdateStyleIndex(); document.FixDomState(); //ClearElementsForSerialize(document); ser.Serialize(writer, document); document.FixDomState(); //ClearElementsForSerialize(document); //document._xmlSerializing = false; }
/// <summary> /// 根据内容创建一个新的文档对象,而且不包含已经被逻辑删除的内容. /// </summary> /// <returns>创建的文档对象</returns> public DomDocument CreateDocument() { DomDocument document = ( DomDocument )this.Document.Clone(false); DomDocument sourceDocument = this.Document; DomContainerElement body = document.Body; // 寻找所有内容共同的文档容器元素 DomElementList parents1 = WriterUtils.GetParentList(this.ContentElements.FirstElement); DomElementList parents2 = WriterUtils.GetParentList(this.ContentElements.LastElement); foreach (DomContainerElement parent in parents1) { if (parents2.Contains(parent)) { DomContentElement ce = parent.ContentElement; CloneElements(parent, ref body); break; } } //CloneElements(this.DocumentContent, ref body ); // 删除用户操作历史记录信息 foreach (DocumentContentStyle style in document.ContentStyles.Styles) { style.CreatorIndex = -1; style.DeleterIndex = -1; } document.UserHistories.Clear(); // 删除没有引用的样式 document.DeleteUselessStyle(); document.EditorControl = null; document.DocumentControler = null; document.HighlightManager = null; document.EditorCurrentStyle = null; document.HoverElement = null; if (document.UndoList != null) { document.EndLogUndo(); document.UndoList.Clear(); } document.FixDomState(); return(document); }