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

Breadcrumb

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

function ResourceFetcher::parseResourceXml

Parses XML resource data.

Parameters

string $data: The raw XML for the resource.

string $url: The resource URL.

Return value

array The parsed resource data.

Throws

\Drupal\media\OEmbed\ResourceException If the resource data could not be parsed.

1 call to ResourceFetcher::parseResourceXml()
ResourceFetcher::fetchResource in core/modules/media/src/OEmbed/ResourceFetcher.php

File

core/modules/media/src/OEmbed/ResourceFetcher.php, line 206

Class

ResourceFetcher
Fetches and caches oEmbed resources.

Namespace

Drupal\media\OEmbed

Code

protected function parseResourceXml($data, $url) {
    // Enable userspace error handling.
    $was_using_internal_errors = libxml_use_internal_errors(TRUE);
    libxml_clear_errors();
    $content = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
    // Restore the previous error handling behavior.
    libxml_use_internal_errors($was_using_internal_errors);
    $error = libxml_get_last_error();
    if ($error) {
        libxml_clear_errors();
        throw new ResourceException($error->message, $url);
    }
    elseif ($content === FALSE) {
        throw new ResourceException('The fetched resource could not be parsed.', $url);
    }
    // Convert XML to JSON so that the parsed resource has a consistent array
    // structure, regardless of any XML attributes or quirks of the XML parser.
    $data = Json::encode($content);
    return Json::decode($data);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal