36132-vm/validators/xml_validator.php
Flatlogic Bot 73a17ab8b2 1
2025-11-24 08:20:21 +00:00

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;
}
}
?>