Esempio n. 1
0
        public static XDocument zGetXDocument(this HttpResult <string> httpResult)
        {
            XDocument xml = null;

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

            //if (http.ExportResult && http.ExportDirectory != null)
            //{
            //    string xmlExportPath = http.GetNewHttpFileName(http.ExportDirectory, ".xml");
            //    xml.Save(xmlExportPath);
            //}
            return(xml);
        }
Esempio n. 2
0
 public static XDocument GetXDocument()
 {
     if (_xdocument == null)
     {
         if (_xdocumentSourceType == XmlDocumentSourceType.Http)
         {
             //__xDocument = __http.zGetXDocument();
             //_xdocument = HttpManager.CurrentHttpManager.GetXDocument(__http);
             _xdocument = _httpResult.zGetXDocument();
         }
         else if (_xdocumentSourceType == XmlDocumentSourceType.XmlFile)
         {
             _xdocument = XDocument.Load(_xmlFile);
         }
         else if (_xdocumentSourceType == XmlDocumentSourceType.HtmlString)
         {
             if (_html != null)
             {
                 using (StringReader sr = new StringReader(_html))
                 {
                     HtmlToXml_v3 hx = new HtmlToXml_v3(new HtmlReader_v4(sr));
                     //hx.ReadCommentInText = _webReadCommentInText;
                     _xdocument = hx.CreateXml();
                 }
             }
         }
     }
     return(_xdocument);
 }
Esempio n. 3
0
        public static void FileHtmlToXml_v2(string file, string xmlFile, bool traceHtmlReader = false, bool traceHtmlToXml = false)
        {
            //HtmlReaderOptions options = HtmlReaderOptions.Default | HtmlReaderOptions.GenerateCloseTag;
            HtmlReaderOptions options = HtmlReaderOptions.Default;

            if (traceHtmlReader)
            {
                HtmlReader_v4.ReadFile(file, options: options | HtmlReaderOptions.DisableLineColumn).zSave(GetFile(file, ".HtmlReader.v4.txt"), jsonIndent: true);
            }

            using (StreamReader sr = zfile.OpenText(file))
            {
                HtmlReader_v4 htmlReader = new HtmlReader_v4(sr, options);
                HtmlToXml_v3  htmlToXml  = new HtmlToXml_v3(htmlReader);
                htmlToXml.CreateXml().Save(xmlFile);
                if (traceHtmlToXml)
                {
                    htmlToXml.Log.zSave(GetFile(file, ".HtmlToXml.v2.json"));
                }
            }
        }