| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | class XMLValidator2 { |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | public function validate($xmlString, $schemaFile, Simplelog $log, $igsn, $file, $i) { |
| 21: | |
| 22: | $dom = new DOMDocument(); |
| 23: | $dom->loadXML($xmlString); |
| 24: | $schema = new DOMDocument(); |
| 25: | $schema->load($schemaFile); |
| 26: | $validator = new DOMDocument(); |
| 27: | $validator->schemaValidate($schemaFile); |
| 28: | libxml_use_internal_errors(true); |
| 29: | if ($dom->schemaValidate($schemaFile)) { |
| 30: | libxml_clear_errors(); |
| 31: | $log->logmessage($igsn. 'is valid__ Line:' .$i); |
| 32: | return true; |
| 33: | } else { |
| 34: | $errors = libxml_get_errors(); |
| 35: | foreach ($errors as $error) { |
| 36: | if ($error->code != 1872) { |
| 37: | $log->logmessage('The '.$file. ' contains errors at IGSN:' . $igsn. 'Line'. $i); |
| 38: | $log->logmessage($error->message); |
| 39: | |
| 40: | } |
| 41: | } |
| 42: | libxml_clear_errors(); |
| 43: | } |
| 44: | } |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | public function validateOnline($xmlString, $source, Simplelog $log, $igsn, $file, $i) { |
| 50: | |
| 51: | $dom = new DOMDocument(); |
| 52: | $dom->loadXML($xmlString); |
| 53: | $schema = new DOMDocument(); |
| 54: | $schema->loadXML($source); |
| 55: | $schemaFile = $schema->saveXML(); |
| 56: | $validator = new DOMDocument(); |
| 57: | libxml_use_internal_errors(true); |
| 58: | |
| 59: | if ($dom->schemaValidate($schemaFile)) { |
| 60: | libxml_clear_errors(); |
| 61: | return true; |
| 62: | } else { |
| 63: | $errors = libxml_get_errors(); |
| 64: | foreach ($errors as $error) { |
| 65: | if ($error->code != 1872) { |
| 66: | $log->logmessage('The '.$file. ' contains errors at IGSN:' . $igsn. ' Line '. $i); |
| 67: | $log->logmessage($error->message); |
| 68: | } |
| 69: | } |
| 70: | libxml_clear_errors(); |
| 71: | } |
| 72: | } |
| 73: | } |
| 74: | |