Tries to get DOM Document from HTML Content or logs Errors and throws Exception.
@access		public
@param		string		$content		HTML Content
@param		string		$url			URL of HTML Page
@return		DOMDocument
493099
protected function getDocument( $content, $url )
	{
		$doc = new DOMDocument();
		ob_start();
		if( !@$doc->loadHTML( $content ) )
		{
			$content	= ob_get_clean();
			if( $content )
				$this->errors[$url]	= $content;
			throw new RuntimeException( 'Error reading HTML.' );
		}
		ob_end_clean();
		return $doc;
	}
537213
public function setDocument($url, RemoteDocument $document)
    {
        // Process the context
        if (isset($document->document->{'@context'}) && is_object($document->document->{'@context'})) {
            $this->processContext((array)$document->document->{'@context'});
        }

        // Save the document to the cache
        $docUrlHash     = $this->getCacheHash($url, self::SLOT_DOC);
        $cachedDocument = Cache::getAdapter()->getItem($docUrlHash);
        $cachedDocument->set($document);
        Cache::getAdapter()->save($cachedDocument);

        // Return the document
        return $document;
    }
1190232
public function get($url) {
    $body = '';
    
    $fp = @fsockopen($this->host, 80, $errno, $errstr);
    if(!$fp) {
      $msg = "Failed to open connection {$this->host} $errno $errstr";
      throw new Exception($msg);
    }
    
    fwrite($fp, $this->buildHeader($url));
    $headerFound = false;
    while(!feof($fp)) {
      $line = fgets($fp);
      if($line === "\r\n") {
        $headerFound = true;
        $line = '';
      }
      if($headerFound) {
        $body .= $line;
      }
    }
    fclose($fp);
    
    $xml = @simplexml_load_string($body);
    if(!$xml) {
      throw new Exception('Unable to load xml result');
    }
    
    return $xml;
  }
803165
public static Document getEventDocFromUrl(String url) throws TVRageException {
        Document doc;
        InputStream in = null;

        try {
            in = new ByteArrayInputStream(requestWebContent(url));

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(in);
            doc.getDocumentElement().normalize();
            return doc;
        } catch (ParserConfigurationException | SAXException | IOException ex) {
            throw new TVRageException(ApiExceptionType.MAPPING_FAILED, UNABLE_TO_PARSE, url, ex);
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                // Input Stream was already closed or null
                LOG.trace("Stream already closed for getEventDocFromUrl", ex);
            }
        }
    }
1235725
public static function getParser($url, $contentDiv, $additionalSetting = false)
    {
        $html = HtmlDomParser::file_get_html($url)->find($contentDiv, 0);
        $html = !$additionalSetting ? $html : $html->next_sibling();
        $html = $html->outertext;
        $html = str_replace('&quot;', '\"', $html);
        $html = str_replace('&lt;', '&l-t;', $html); // handle '<'
        $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
        $html = str_replace('&l-t;', '&lt;', $html);
        $html = HtmlDomParser::str_get_html($html);

        return $html;
    }
1077378
private function query($url, $content, $class)
  {
    $response = null;
    $tries = 0;
    $lastError = null;

    while ($tries < self::MAX_TRIES) {
      try {
        $response = $this->execute($url, $content, $tries);
        break;
      } catch (Exception $e) {
        usleep(self::RETRY_TIMEOUT);
        error_log('Connection failed, retrying');
        $lastError = $e;
        $tries++;
      }
    }

    if ($tries == self::MAX_TRIES) {
      throw new RuntimeException("Error: call to URL $url failed after " . self::MAX_TRIES . " tries", 0, $lastError);
    }

    if ($response->hasErrors()) {
      throw new RuntimeException("Error: call to URL $url failed with status $response->code, response $response");
    }

    if ($response->content_type !== Mime::JSON) {
      throw new RuntimeException("Error: bridge at URL $url did not return the expected JSON response, it returned: " . $response->content_type . " instead");
    }

    $responseBody = $response->raw_body;
    if (strpos($this->getContentEncoding($response), 'gzip') !== FALSE) {
      $responseBody = gzdecode($responseBody);
    }

    return $this->deserialize($responseBody, $class);
  }
288287
public static Element getContentElementByHtml(String html) throws Exception {
        Document doc = Jsoup.parse(html);
        return getContentElementByDoc(doc);
    }
31363
protected function getRemoteContent($url)
    {
        $response = (new Client())
            ->createRequest()
            ->setMethod('GET')
            ->setUrl($url)
            ->send();
        if (!$response->isOk) {
            throw new Exception("URL {$url} doesn't exist");
        }

        return $response->content;
    }
210099
public static function loadFromUrl(string $url, array $options = [], CurlInterface $curl = null): Dom
    {
        $dom       = new Dom;
        self::$dom = $dom;
        if (is_null($curl)) {
            // use the default curl interface
            $curl = new Curl;
        }

        return $dom->loadFromUrl($url, $options, $curl);
    }
54900
protected function createDomDocument($html): \DOMDocument
    {
        $document = new \DOMDocument('1.0');
        $previousValue = libxml_use_internal_errors(true);
        libxml_clear_errors();
        $document->loadHTML($html);
        /** @var \LibXMLError[] $errors */
        $errors = libxml_get_errors();
        libxml_clear_errors();
        libxml_use_internal_errors($previousValue);

        foreach ($errors as $error) {
            if (LIBXML_ERR_ERROR === $error->level || LIBXML_ERR_FATAL === $error->level) {
                throw new SourceException(
                    sprintf('%s at %d:%d', trim($error->message), $error->line, $error->column),
                    $error->code
                );
            }
        }

        return $document;
    }
400352
protected function read(Url $url)
    {
        /** @var Response $response */
        try {
            $response = $this->getHttpInvoker()->get((string) $url);
        } catch (RequestException $exception) {
            $code = 0;
            $message = null;
            if ($exception->getResponse()) {
                $code = $exception->getResponse()->getStatusCode();
                $message = $exception->getResponse()->getBody();
            }
            throw $this->convertStatusCode(
                $code,
                (string) $message,
                $exception
            );
        }

        return $response;
    }
304042
private function get($url)
    {
        try {
            $result = $this->fileHelper->getContents(
                $url,
                $this->config->get('concrete.marektplace.request_timeout'));
        } catch (TimeoutException $e) {
            // Catch a timeout
            $this->connectionError = self::E_CONNECTION_TIMEOUT;

            return null;
        } catch (Exception $e) {
            $this->connectionError = self::E_GENERAL_CONNECTION_ERROR;

            return null;
        }

        return $result ?: null;
    }
1210476
public function loadString($str, $url = null)
    {
        $this->_str = $str;

        $this->_dom = new \DOMDocument();
        $this->_dom->strictErrorChecking = false;

        libxml_clear_errors();
        $old_use_internal_errors = libxml_use_internal_errors(true);
        $old_disable_entity_loader = libxml_disable_entity_loader(true);

        /** @noinspection SubStrUsedAsStrPosInspection */
        if (substr($str, 0, 5) === '<?xml') {
            $r = $this->_dom->loadXML($str);
        } else {
            $r = $this->_dom->loadHTML($str, LIBXML_HTML_NODEFDTD);
        }

        $this->_domErrors = libxml_get_errors();
        libxml_clear_errors();

        libxml_disable_entity_loader($old_disable_entity_loader);
        libxml_use_internal_errors($old_use_internal_errors);

        if (!$r) {
            throw new DocumentException('xx');
        }

        $this->_query = new Query($this->_dom);

        $this->_sourceUrl = $url;
        $this->_baseUrl = $this->_getBaseUrl() ?: $this->_sourceUrl;

        return $this;
    }
175124
public static function getDOM($str)
	{
		//create domdocument
		$dom = new DOMDocument();
		//load by file or string
		is_file($str) ? $dom->load($str) : $dom->loadXML($str);
		// return the DOMDoc
		return $dom;
	}
439336
protected final function loadHTML(DOMDocument $dom, string $html)
   {
       try {
           $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
       } catch (Throwable $e) {
           throw new RuntimeException("Can't load HTML: " . $e->getMessage());
       }
   }
109396
private function getDomDocument(string $src){
        if(strtolower(substr($src, 0, 14)) !== "<!doctype html"){
            return null;
        }

        $dom    = new \DOMDocument();
        @$dom->loadHTML($src);

        return $dom;
    }
899832
function (html, url) {
      this.html = html;
      var doc = this.doc = new Document(url);
      this.readChildren(doc);

      // If this is an HTML document, remove root-level children except for the
      // <html> node
      if (doc.documentElement) {
        for (var i = doc.childNodes.length; --i >= 0;) {
          var child = doc.childNodes[i];
          if (child !== doc.documentElement) {
            doc.removeChild(child);
          }
        }
      }

      return doc;
    }