index 690ee7f2c0dedec7cc9a6e25798d9ffdaee3849b..bb79e33e326444cc5249ae4557be4d459a55171e 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) {
+ $estr= "";
+ switch ($error->level) {
+ case LIBXML_ERR_WARNING:
+ $estr= _("Warning")." ".$error->code.":";
+ break;
+ case LIBXML_ERR_ERROR:
+ $estr= _("Error")." ".$error->code.":";
+ break;
+ case LIBXML_ERR_FATAL:
+ $estr= _("Fatal error")." ".$error->code.":";
+ break;
+ }
+ if ($error->file) {
+ $str= sprintf("%s %s in %s", $estr, trim($error->message), $error->file);
+ } else {
+ $str= sprintf("%s %s in %s on line %s", $estr, trim($error->message), $error->file, $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();
//See tag status and do the needed.
if($type == "open") {//The starting of the tag '<tag>'
$parent[$level-1] = &$current;
- if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
+ if(!is_array($current) or (!in_array_strict($tag, array_keys($current)))) { //Insert New tag
$current[$tag] = $result;
if($attributes_data) $current[$tag. '_attr'] = $attributes_data;
$repeated_tag_index[$tag.'_'.$level] = 1;
return($xml_array);
}
+
}