Example #1
0
        public static XDocument GetXDocument()
        {
            if (__xDocument == null)
            {
                if (__xmlDocumentSourceType == XmlDocumentSourceType.Http)
                {
                    //__xDocument = __http.zGetXDocument();
                    __xDocument = HttpManager.CurrentHttpManager.GetXDocument(__http);
                }
                else if (__xmlDocumentSourceType == XmlDocumentSourceType.XmlFile)
                {
                    __xDocument = XDocument.Load(__xmlFile);
                }
                else if (__xmlDocumentSourceType == XmlDocumentSourceType.HtmlString)
                {
                    if (__html != null)
                    {
                        using (StringReader sr = new StringReader(__html))
                        {
                            HtmlToXml_v2 hx = new HtmlToXml_v2(sr);
                            //hx.ReadCommentInText = _webReadCommentInText;
                            __xDocument = hx.GenerateXDocument();
                        }

                        //if (_trace.TraceLevel >= 2)
                        //{
                        //    string sPath = GetNewFileName();
                        //    if (_xDocument != null && sPath != null) _xDocument.Save(sPath + "_LoadHtmlString.xml");
                        //}
                    }
                }
            }
            return(__xDocument);
        }
Example #2
0
        public static XDocument zGetXDocument(this Http http)
        {
            XDocument xml = null;

            if (http.ResultContentType == "text/html")
            {
                HtmlToXml_v2 hx = new HtmlToXml_v2(new StringReader(http.ResultText));
                //hx.ReadCommentInText = _readCommentInText;
                xml = hx.GenerateXDocument();
            }
            else if (http.ResultContentType == "text/xml")
            {
                xml = XDocument.Parse(http.ResultText, LoadOptions.PreserveWhitespace);
            }
            else
            {
                throw new PBException("Error can't transform http content \"{0}\" to xml", http.ResultContentType);
            }

            //if (http.ExportResult && http.ExportDirectory != null)
            //{
            //    string xmlExportPath = http.GetNewHttpFileName(http.ExportDirectory, ".xml");
            //    xml.Save(xmlExportPath);
            //}
            return(xml);
        }
Example #3
0
 public static void FileHtmlToXml(string file, string xmlFile, string traceHtmlReaderFile, int htmlReaderVersion = 2, Encoding encoding = null)
 {
     //using (StreamReader sr = zFile.OpenText(file))
     using (StreamReader sr = zfile.OpenText(file, encoding))
     {
         HtmlReader.TraceHtmlReaderFile    = traceHtmlReaderFile;
         HtmlReader_v2.TraceHtmlReaderFile = traceHtmlReaderFile;
         //HtmlReader htmlReader = new HtmlReader(sr);
         //htmlReader.TraceHtmlReaderFile = traceHtmlReaderFile;
         //HtmlToXml hx = new HtmlToXml(htmlReader);
         HtmlToXml_v2.HtmlReaderVersion = htmlReaderVersion;
         HtmlToXml_v2 hx = new HtmlToXml_v2(sr);
         //hx.ReadCommentInText = _readCommentInText;
         //file = zpath.PathSetExtension(file, ".xml");
         hx.GenerateXDocument().Save(xmlFile);
     }
 }
Example #4
0
        public static void FileHtmlToXml_HtmlReader_v2(string file, string xmlFile, string traceHtmlReaderFile, string traceHtmlToXmlFile, bool useXDocumentCreator = false, bool correctionMarkBeginEnd = false, Encoding encoding = null)
        {
            try
            {
                if (traceHtmlReaderFile != null)
                {
                    __srTraceHtmlReader        = zFile.CreateText(traceHtmlReaderFile);
                    __traceJsonSettings        = new JsonWriterSettings();
                    __traceJsonSettings.Indent = true;
                }

                using (StreamReader sr = zfile.OpenText(file, encoding))
                {
                    //HtmlReader.TraceHtmlReaderFile = traceHtmlReaderFile;
                    //HtmlReader_v2.TraceHtmlReaderFile = traceHtmlReaderFile;
                    //HtmlToXml.HtmlReaderVersion = htmlReaderVersion;
                    HtmlReader_v2 htmlReader = new HtmlReader_v2(sr);
                    //htmlReader.Trace += TraceHtmlReader;
                    htmlReader.Trace = TraceHtmlReader;
                    //HtmlToXml hx = new HtmlToXml(sr);
                    HtmlToXml_v2 hx = new HtmlToXml_v2(htmlReader);
                    hx.UseXDocumentCreator    = useXDocumentCreator;
                    hx.CorrectionMarkBeginEnd = correctionMarkBeginEnd;
                    hx.GenerateXDocument().Save(xmlFile);
                    if (useXDocumentCreator && traceHtmlToXmlFile != null)
                    {
                        hx.Log.zSave(traceHtmlToXmlFile);
                    }
                }
            }
            finally
            {
                if (__srTraceHtmlReader != null)
                {
                    __srTraceHtmlReader.Close();
                    __srTraceHtmlReader = null;
                }
                __traceJsonSettings = null;
            }
        }