Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/FluidXml/FluidInsertionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ protected function attachNodes($parent, $nodes, $fn): array
$context = [];

foreach ($nodes as $el) {
// DOMDocumentType cannot be imported as a child node.
if ($el instanceof \DOMDocumentType) {
continue;
}

$el = $this->dom->importNode($el, true);
$context[] = $fn($parent, $el);
}
Expand Down
28 changes: 28 additions & 0 deletions specs/FluidXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,34 @@

assert_is_a($actual, \Exception::class);
});

it('should import an XML file containing a DOCTYPE declaration', function () {
$file = "{$this->out_dir}.test_load_doctype.xml";
$doc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
. "<!DOCTYPE fcpxml>\n"
. "<fcpxml version=\"1.8\"><resources/></fcpxml>";

\file_put_contents($file, $doc);
$xml = FluidXml::load($file);
\unlink($file);

$expected = "<fcpxml version=\"1.8\">\n <resources/>\n</fcpxml>";
assert_equal_xml($xml, $expected);
});
});

describe('.addChild() with DOCTYPE', function () {
it('should not throw when adding an XML string with a DOCTYPE declaration', function () {
$xml = new FluidXml(null);
$xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
. "<!DOCTYPE fcpxml>\n"
. "<fcpxml version=\"1.8\"><resources/></fcpxml>";

$xml->addChild($xmlStr);

$expected = "<fcpxml version=\"1.8\">\n <resources/>\n</fcpxml>";
assert_equal_xml($xml, $expected);
});
});

if (\version_compare(\phpversion(), '7', '>=')) {
Expand Down