Ejemplo n.º 1
0
        public static DomDocument LoadXmlFileWithCreateDocument(
            System.IO.Stream stream,
            DomDocument sourceDocument)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            XmlSerializer ser = DocumentSaver.GetDocumentXmlSerializer(
                sourceDocument == null ? typeof(DomDocument) : sourceDocument.GetType());

            System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(stream);
            reader.Normalization = false;
            DomDocument document = ( DomDocument )ser.Deserialize(reader);

            if (string.Compare(document.EditorVersionString, "1.1") < 0)
            {
                // 修复ListSource
            }
            if (sourceDocument != null)
            {
                document.ServerObject = sourceDocument.ServerObject;
                document.Options      = sourceDocument.Options;
            }
            document.AfterLoad(FileFormat.XML);
            return(document);
        }
Ejemplo n.º 2
0
        public static void LoadXmlFile(
            System.IO.TextReader reader,
            DomDocument document)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            DomDocument tempDoc = LoadXmlFileWithCreateDocument(reader, document);

            if (tempDoc != null)
            {
                //string txt = tempDoc.GetDebugText() ;
                //System.Windows.Forms.MessageBox.Show(txt);
                document.CopyContent(tempDoc, true);
                document.AfterLoad(FileFormat.XML);
                //txt = txt + "\r\n------------\r\n" + document.GetDebugText();
                //System.Windows.Forms.MessageBox.Show(txt);
            }
            else
            {
                //System.Windows.Forms.MessageBox.Show("Load NULL");
            }
        }
Ejemplo n.º 3
0
        public static void LoadTextFile(string fileName, DomDocument document)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (System.IO.File.Exists(fileName) == false)
            {
                throw new System.IO.FileNotFoundException(fileName);
            }

            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            using (StreamReader reader = new StreamReader(
                       fileName,
                       Encoding.Default,
                       true))
            {
                string txt = reader.ReadToEnd();
                document.Text = txt;
                document.AfterLoad(FileFormat.Text);
                document.Modified = false;
            }
        }
Ejemplo n.º 4
0
        public static void LoadHtmlFile(
            System.IO.TextReader reader,
            DomDocument document,
            string baseUrl)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            HTMLDocument htmlDoc = new HTMLDocument();
            string       html    = reader.ReadToEnd();

            htmlDoc.LoadHTML(html);
            if (string.IsNullOrEmpty(baseUrl) == false)
            {
                htmlDoc.BaseURL = baseUrl;
            }
            HtmlLoader loader = new HtmlLoader();

            loader.Load(htmlDoc, document);
            document.AfterLoad(FileFormat.Html);
        }
Ejemplo n.º 5
0
        public static DomDocument LoadXmlFileWithCreateDocument(
            System.Xml.XmlReader reader,
            DomDocument sourceDocument)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            XmlSerializer ser = DocumentSaver.GetDocumentXmlSerializer(
                sourceDocument == null ? typeof(DomDocument) : sourceDocument.GetType());

            if (reader is System.Xml.XmlTextReader)
            {
                ((System.Xml.XmlTextReader)reader).Normalization = false;
            }
            DomDocument document = (DomDocument)ser.Deserialize(reader);

            if (sourceDocument != null)
            {
                document.ServerObject = sourceDocument.ServerObject;
                document.Options      = sourceDocument.Options;
            }
            document.AfterLoad(FileFormat.XML);
            return(document);
        }
Ejemplo n.º 6
0
        public static void LoadTextFile(TextReader reader, DomDocument document)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            string txt = reader.ReadToEnd();

            document.Text = txt;
            document.AfterLoad(FileFormat.Text);
            document.Modified = false;
        }
Ejemplo n.º 7
0
        public static void LoadHtmlFile(
            string url,
            DomDocument document)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            HTMLDocument htmlDoc = new HTMLDocument();

            htmlDoc.LoadUrl(url);
            document.BaseUrl = htmlDoc.BaseURL;
            HtmlLoader loader = new HtmlLoader();

            loader.Load(htmlDoc, document);
            document.AfterLoad(FileFormat.Html);
        }
Ejemplo n.º 8
0
        public static void LoadXmlFile(
            System.IO.Stream stream,
            DomDocument document)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            DomDocument doc = LoadXmlFileWithCreateDocument(stream, document);

            if (doc != null)
            {
                document.CopyContent(doc, true);
                document.AfterLoad(FileFormat.XML);
            }
        }
Ejemplo n.º 9
0
        public static void LoadHtmlFile(
            System.IO.Stream stream,
            DomDocument document,
            string baseUrl)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            HTMLDocument htmlDoc = new HTMLDocument();

            htmlDoc.Load(stream);
            htmlDoc.BaseURL = baseUrl;
            HtmlLoader loader = new HtmlLoader();

            loader.Load(htmlDoc, document);
            document.AfterLoad(FileFormat.Html);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 从RTF文档生成文本文档内容对象
        /// </summary>
        /// <param name="document">文本文档对象</param>
        /// <returns>包含生成的内容对象的列表</returns>
        public void ReadContent(DomDocument document)
        {
            document.Clear();
            if (this.EnableDocumentSetting)
            {
                XPageSettings ps = new XPageSettings();
                ps.Landscape  = _RTFDocument.Landscape;
                ps.LeftMargin = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.LeftMargin, GraphicsUnit.Document) / 3;
                ps.TopMargin = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.TopMargin, GraphicsUnit.Document) / 3;
                ps.RightMargin = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.RightMargin, GraphicsUnit.Document) / 3;
                ps.BottomMargin = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.BottomMargin, GraphicsUnit.Document) / 3;
                ps.PaperWidth = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.PaperWidth, GraphicsUnit.Document) / 3;
                ps.PaperHeight = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.PaperHeight, GraphicsUnit.Document) / 3;
                document.PageSettings = ps;

                document.Info.Title            = _RTFDocument.Info.Title;
                document.Info.Author           = _RTFDocument.Info.Author;
                document.Info.CreationTime     = _RTFDocument.Info.Creatim;
                document.Info.Description      = _RTFDocument.Info.Comment;
                document.Info.LastPrintTime    = _RTFDocument.Info.Printim;
                document.Info.LastModifiedTime = _RTFDocument.Info.Revtim;
                document.Info.EditMinute       = _RTFDocument.Info.edmins;
            }
            document.Elements.Clear();
            document.Initializing = true;
            ReadContent(
                _RTFDocument,
                document,
                document.Elements,
                new DocumentFormatInfo());
            document.Initializing = false;
            document.AfterLoad(FileFormat.RTF);
        }
Ejemplo n.º 11
0
 public static void LoadTextFile(
     Stream stream,
     DomDocument document)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     using (StreamReader reader = new StreamReader(
                stream,
                Encoding.Default,
                true))
     {
         string txt = reader.ReadToEnd();
         document.Text = txt;
         document.AfterLoad(FileFormat.Text);
         document.Modified = false;
     }
 }
Ejemplo n.º 12
0
        public static void LoadXmlFile(
            string fileName,
            DomDocument document)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (System.IO.File.Exists(fileName) == false)
            {
                throw new System.IO.FileNotFoundException(fileName);
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            DomDocument doc = LoadXmlFileWithCreateDocument(fileName, document);

            if (doc != null)
            {
                document.CopyContent(doc, true);
                document.AfterLoad(FileFormat.XML);
            }
        }