Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Crawler.php

function Crawler::addXmlContent

Adds an XML content to the list of nodes.

The libxml errors are disabled when the content is parsed.

If you want to get parsing errors, be sure to enable internal errors via libxml_use_internal_errors(true) and then, get the errors via libxml_get_errors(). Be sure to clear errors with libxml_clear_errors() afterward.

Parameters

int $options Bitwise OR of the libxml option constants: LIBXML_PARSEHUGE is dangerous, see http://symfony.com/blog/security-release-symfony-2-0-17-released

1 call to Crawler::addXmlContent()
Crawler::addContent in vendor/symfony/dom-crawler/Crawler.php
Adds HTML/XML content.

File

vendor/symfony/dom-crawler/Crawler.php, line 206

Class

Crawler
Crawler eases navigation of a list of \DOMNode objects.

Namespace

Symfony\Component\DomCrawler

Code

public function addXmlContent(string $content, string $charset = 'UTF-8', int $options = \LIBXML_NONET) : void {
    // remove the default namespace if it's the only namespace to make XPath expressions simpler
    if (!str_contains($content, 'xmlns:')) {
        $content = str_replace('xmlns', 'ns', $content);
    }
    $internalErrors = libxml_use_internal_errors(true);
    $dom = new \DOMDocument('1.0', $charset);
    $dom->validateOnParse = true;
    if ('' !== trim($content)) {
        @$dom->loadXML($content, $options);
    }
    libxml_use_internal_errors($internalErrors);
    $this->addDocument($dom);
    $this->isHtml = false;
}
RSS feed
Powered by Drupal