public static function import($file) { libxml_use_internal_errors(true); $xml = new DOMDocument(); if (!$xml->loadXML($file)) { $text = ''; foreach (libxml_get_errors() as $error) { switch ($error->level) { case LIBXML_ERR_WARNING: $text .= _('XML file contains errors') . '. Warning ' . $error->code . ': '; break; case LIBXML_ERR_ERROR: $text .= _('XML file contains errors') . '. Error ' . $error->code . ': '; break; case LIBXML_ERR_FATAL: $text .= _('XML file contains errors') . '. Fatal Error ' . $error->code . ': '; break; } $text .= trim($error->message) . ' [ Line: ' . $error->line . ' | Column: ' . $error->column . ' ]'; break; } libxml_clear_errors(); throw new Exception($text); } if ($xml->childNodes->item(0)->nodeName != 'zabbix_export') { $xml2 = self::createDOMDocument(); $xml2->appendChild($xml2->ownerDocument->importNode($xml->childNodes->item(0), true)); self::$xml = $xml2->ownerDocument; } else { self::$xml = $xml; } return true; }
public static function import($source) { libxml_use_internal_errors(true); libxml_disable_entity_loader(true); $xml = new DOMDocument(); if (!$xml->loadXML($source, LIBXML_IMPORT_FLAGS)) { $text = ''; foreach (libxml_get_errors() as $error) { switch ($error->level) { case LIBXML_ERR_WARNING: $text .= _('XML file contains errors') . '. Warning ' . $error->code . ': '; break; case LIBXML_ERR_ERROR: $text .= _('XML file contains errors') . '. Error ' . $error->code . ': '; break; case LIBXML_ERR_FATAL: $text .= _('XML file contains errors') . '. Fatal Error ' . $error->code . ': '; break; } $text .= trim($error->message) . ' [ Line: ' . $error->line . ' | Column: ' . $error->column . ' ]'; break; } libxml_clear_errors(); throw new Exception($text); } self::$xml = $xml; return true; }