29 lines
937 B
PHP
29 lines
937 B
PHP
<?php
|
|
class XmlValidator {
|
|
public static function validate($xmlString) {
|
|
$errors = [];
|
|
$dom = new DOMDocument();
|
|
if (!@$dom->loadXML($xmlString)) {
|
|
$errors[] = "Failed to parse XML.";
|
|
return $errors;
|
|
}
|
|
|
|
$rootElement = $dom->documentElement;
|
|
if ($rootElement->tagName !== 'ectd:ectd') {
|
|
$errors[] = "Root element is not 'ectd:ectd'.";
|
|
}
|
|
|
|
$dtdVersion = $dom->getElementsByTagName('dtd-version')->item(0);
|
|
if (!$dtdVersion || empty($dtdVersion->nodeValue)) {
|
|
$errors[] = "Required tag 'dtd-version' is missing or empty.";
|
|
}
|
|
|
|
$submissionType = $dom->getElementsByTagName('submission-type')->item(0);
|
|
if (!$submissionType || empty($submissionType->nodeValue)) {
|
|
$errors[] = "Required tag 'submission-type' is missing or empty.";
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
}
|
|
?>
|