Example #1
0
        public static XDocument zGetXDocument(this Http http)
        {
            XDocument xml = null;
            if (http.ResultContentType == "text/html")
            {
                HtmlToXml hx = new HtmlToXml(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 #2
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 hx = new HtmlToXml(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;
        }