public static function importXML(NodeInterface $parentNode, NamespaceRegistryInterface $ns, $uri, $uuidBehavior)
{
$use_errors = libxml_use_internal_errors(true);
libxml_clear_errors();
if (!file_exists($uri)) {
throw new \RuntimeException("File {$uri} does not exist or is not readable");
}
$xml = new FilteredXMLReader();
$options = 0;
if (LIBXML_VERSION >= 20700) {
$options = LIBXML_PARSEHUGE;
}
$xml->open($uri, null, $options);
if (libxml_get_errors()) {
libxml_use_internal_errors($use_errors);
throw new InvalidSerializedDataException("Invalid xml file {$uri}");
}
$xml->read();
try {
if ('node' === $xml->localName && NamespaceRegistryInterface::NAMESPACE_SV === $xml->namespaceURI) {
// TODO: validate with DTD?
self::importSystemView($parentNode, $ns, $xml, $uuidBehavior);
} else {
self::importDocumentView($parentNode, $ns, $xml, $uuidBehavior);
}
} catch (\Exception $e) {
// restore libxml setting
libxml_use_internal_errors($use_errors);
// and rethrow exception to not hide it
throw $e;
}
libxml_use_internal_errors($use_errors);
}