You are here

protected static function XmlParserTrait::getDomDocument in Feeds 8.3

Returns a new DOMDocument.

Implementers can override this to setup the document.

Parameters

string $source: The XML string to parse.

int $options: (optional) Bitwise OR of the libxml option constants. Defaults to 0.

Return value

\DOMDocuemnt The new DOMDocument object.

Throws

\RuntimeException Thrown if the document fails to load.

2 calls to XmlParserTrait::getDomDocument()
GenericOpmlParser::__construct in src/Component/GenericOpmlParser.php
Constructs a GenericOpmlParser object.
HttpHelpers::findRelationFromXml in src/Component/HttpHelpers.php
Finds a link relation in XML.

File

src/Component/XmlParserTrait.php, line 54

Class

XmlParserTrait
Helper methods for dealing with XML documents.

Namespace

Drupal\feeds\Component

Code

protected static function getDomDocument($source, $options = 0) {
  static::startXmlErrorHandling();
  $document = new \DOMDocument('1.0', 'utf-8');
  $document->strictErrorChecking = FALSE;
  $document->resolveExternals = FALSE;

  // Libxml specific.
  $document->substituteEntities = FALSE;
  $document->recover = TRUE;
  $options = $options | LIBXML_NOENT | LIBXML_NONET | defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0;
  $options = $options | defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0;
  $document
    ->loadXML($source, $options);
  static::stopXmlErrorHandling();
  return $document;
}