From a310a7953affa6bb27c6fba1de9c1a0a699fcb12 Mon Sep 17 00:00:00 2001 From: cajus Date: Mon, 31 Aug 2009 09:59:15 +0000 Subject: [PATCH] Added validator git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14169 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/utils/class_xml.inc | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gosa-core/include/utils/class_xml.inc b/gosa-core/include/utils/class_xml.inc index 096bb0973..713d09930 100644 --- a/gosa-core/include/utils/class_xml.inc +++ b/gosa-core/include/utils/class_xml.inc @@ -20,6 +20,41 @@ */ class xml { + + static function validate($file, $schema) { + // Enable user error handling + libxml_use_internal_errors(true); + + $xml = new DOMDocument(); + $xml->load($file); + + if (!$xml->schemaValidate($schema)) { + $errors = libxml_get_errors(); + foreach ($errors as $error) { + $str= ""; + switch ($error->level) { + case LIBXML_ERR_WARNING: + $str= _("Warning")." ".$error->code.": "; + break; + case LIBXML_ERR_ERROR: + $str= _("Error")." ".$error->code.": "; + break; + case LIBXML_ERR_FATAL: + $str= _("Fatal error")." ".$error->code.": "; + break; + } + $str.= trim($error->message); + if ($error->file) { + $str.= " "._("in")." ".$error->file; + } + $str.= " "._("on line")." ".$error->line; + msg_dialog::display(_("XML error"), $str, ERROR_DIALOG); + } + libxml_clear_errors(); + } + } + + static function xml2array($contents, $get_attributes=1, $priority = 'tag') { if(!$contents) return array(); -- 2.30.2