class XmlUtility in Feeds extensible parsers 8
Simple XML helpers.
Hierarchy
- class \Drupal\feeds_ex\Utility\XmlUtility uses StringTranslationTrait
Expanded class hierarchy of XmlUtility
6 files declare their use of XmlUtility
- HtmlParserTest.php in tests/
src/ Unit/ Feeds/ Parser/ HtmlParserTest.php - QueryPathHtmlParserTest.php in tests/
src/ Unit/ Feeds/ Parser/ QueryPathHtmlParserTest.php - QueryPathXmlParserTest.php in tests/
src/ Unit/ Feeds/ Parser/ QueryPathXmlParserTest.php - XmlParser.php in src/
Feeds/ Parser/ XmlParser.php - XmlParserTest.php in tests/
src/ Unit/ Feeds/ Parser/ XmlParserTest.php
1 string reference to 'XmlUtility'
1 service uses XmlUtility
File
- src/
Utility/ XmlUtility.php, line 12
Namespace
Drupal\feeds_ex\UtilityView source
class XmlUtility {
use StringTranslationTrait;
/**
* Creates an HTML document.
*
* @param string $source
* The string containing the HTML.
* @param int $options
* (optional) Bitwise OR of the libxml option constants. Defaults to 0.
*
* @return \DOMDocument
* The newly created DOMDocument.
*
* @throws \RuntimeException
* Thrown if there is a fatal error parsing the XML.
*/
public function createHtmlDocument($source, $options = 0) {
// Fun hack to force parsing as utf-8.
$source = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n" . $source;
$document = $this
->buildDomDocument();
$options |= LIBXML_NONET;
$options |= defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0;
$options |= defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0;
$success = $document
->loadHTML($source, $options);
if (!$success) {
throw new RuntimeException($this
->t('There was an error parsing the HTML document.'));
}
return $document;
}
/**
* Converts named HTML entities to their UTF-8 equivalent.
*
* @param string $markup
* The string.
*
* @return string
* The converted string.
*/
public function decodeNamedHtmlEntities($markup) {
$map = array_flip(get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES | ENT_HTML5, 'UTF-8'));
unset($map['&'], $map['<'], $map['>']);
return strtr($markup, $map);
}
/**
* Builds a DOMDocument setting some default values.
*
* @return \DOMDocument
* A new DOMDocument.
*/
protected function buildDomDocument() {
$document = new DOMDocument();
$document->strictErrorChecking = FALSE;
$document->resolveExternals = FALSE;
// Libxml specific.
$document->substituteEntities = FALSE;
$document->recover = TRUE;
return $document;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
XmlUtility:: |
protected | function | Builds a DOMDocument setting some default values. | |
XmlUtility:: |
public | function | Creates an HTML document. | |
XmlUtility:: |
public | function | Converts named HTML entities to their UTF-8 equivalent. |