From: cajus Date: Mon, 31 Aug 2009 09:59:15 +0000 (+0000) Subject: Added validator X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a310a7953affa6bb27c6fba1de9c1a0a699fcb12;p=gosa.git Added validator git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14169 594d385d-05f5-0310-b6e9-bd551577e9d8 --- 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();