diff --git a/source/FluidXml/FluidXml.php b/source/FluidXml/FluidXml.php index 1f8b11d..254a550 100644 --- a/source/FluidXml/FluidXml.php +++ b/source/FluidXml/FluidXml.php @@ -26,17 +26,17 @@ class FluidXml implements FluidInterface private ?\FluidXml\FluidContext $context = null; private $contextEl; - public static function load($document) + public static function load($document, int $flags = 0) { - $file = $document; - $document = \file_get_contents($file); + $dom = new \DOMDocument(); + $dom->formatOutput = true; + $dom->preserveWhiteSpace = false; - // file_get_contents() returns false in case of error. - if (! $document) { - throw new \Exception("File '$file' not accessible."); + if (! @$dom->load($document, $flags)) { + throw new \Exception("File '$document' not accessible."); } - return (new FluidXml(null))->addChild($document); + return (new FluidXml(null))->addChild($dom); } public function __construct(...$arguments) diff --git a/specs/FluidXml.php b/specs/FluidXml.php index 6cac1ef..a331203 100644 --- a/specs/FluidXml.php +++ b/specs/FluidXml.php @@ -142,6 +142,20 @@ assert_is_a($actual, \Exception::class); }); + + it('should accept libxml flags', function () { + $file = "{$this->out_dir}.test_load_flags.xml"; + $doc = "\n" + . " value\n" + . ""; + + \file_put_contents($file, $doc); + $xml = FluidXml::load($file, \LIBXML_PARSEHUGE); + \unlink($file); + + $expected = $doc; + assert_equal_xml($xml, $expected); + }); }); if (\version_compare(\phpversion(), '7', '>=')) {