This package provides a safety way to load string or file to DOMDocument.
You can install this package via composer.
composer require vaclavvanik/dom-loader
<?php
declare(strict_types=1);
use VaclavVanik\DomLoader;
$dom = DomLoader\DomLoader::loadFile($file);
// or
$dom = DomLoader\DomLoader::loadString($string);
passing dom load $options
is also available:
<?php
declare(strict_types=1);
use VaclavVanik\DomLoader;
use const LIBXML_PARSEHUGE;
$dom = DomLoader\DomLoader::loadFile($file, LIBXML_PARSEHUGE);
// or
$dom = DomLoader\DomLoader::loadString($string, LIBXML_PARSEHUGE);
and finally loading into custom DOMDocument is supported:
<?php
declare(strict_types=1);
use DOMDocument;
use VaclavVanik\DomLoader;
$dom = DomLoader\DomLoader::loadFile($file, 0, new DOMDocument('1.0', 'utf-8'));
// or
$dom = DomLoader\DomLoader::loadString($string, 0, new DOMDocument('1.0', 'utf-8'));
load methods throw:
- Exception\LibXml if xml file parsing failed.
- Exception\Runtime if error occurs when reading file.
- Exception\ValueError if filename or xml string is empty.
Install dependencies:
make install
Run check:
make check
Please see CHANGELOG for more information what has changed recently.
The MIT License (MIT). Please see License File for more information.