Beispiel #1
0
 /**
  * Parses the response as an XML / HTML document.
  *
  * If the response is not a valid document, and empty document is returned.
  *
  * @return \DOMDocument
  */
 public function parseDocument()
 {
     $pattern = '/(x|ht)ml(?:.*;charset=(\\S+))?/i';
     $contentType = $this->response->getHeader('Content-Type');
     $isDocument = preg_match($pattern, $contentType, $matches) == 1;
     $charset = isset($matches[2]) ? $matches[2] : 'UTF-8';
     $useInternalErrors = libxml_use_internal_errors(true);
     $disableEntityLoader = libxml_disable_entity_loader(true);
     $document = new \DOMDocument('1.0', $charset);
     $document->validateOnParse = true;
     if ($isDocument) {
         $isXml = strtolower($matches[1]) == 'x';
         if ($isXml) {
             $document->loadXML($this->getText());
         } else {
             $document->loadHTML($this->getText());
         }
     }
     libxml_use_internal_errors($useInternalErrors);
     libxml_disable_entity_loader($disableEntityLoader);
     return $document;
 }