summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f36d8d2)
raw | patch | inline | side by side (parent: f36d8d2)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 31 Aug 2009 09:59:15 +0000 (09:59 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 31 Aug 2009 09:59:15 +0000 (09:59 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14169 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/utils/class_xml.inc | patch | blob | history |
index 096bb0973a0435376108bebf3c580c00ba614638..713d099308d441ad4fa5af35fd346fa85166715f 100644 (file)
*/
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();