Xsd.php 869 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace NavOnlineInvoice;
  3. use DOMDocument;
  4. class Xsd {
  5. /**
  6. * A megadott XML-t (string) ellenőrzi a megadott XSD sémával.
  7. * Hiba esetén XsdValidationError exception-t dob.
  8. *
  9. * @param string $xmlString
  10. * @param string $xsdFilename
  11. * @throws XsdValidationError
  12. */
  13. public static function validate($xmlString, $xsdFilename) {
  14. $doc = new DOMDocument();
  15. $doc->loadXML($xmlString);
  16. $prevValue = libxml_use_internal_errors(true);
  17. libxml_clear_errors();
  18. $isValid = $doc->schemaValidate($xsdFilename);
  19. if (!$isValid) {
  20. $errors = libxml_get_errors();
  21. libxml_clear_errors();
  22. libxml_use_internal_errors($prevValue);
  23. throw new XsdValidationError($errors);
  24. }
  25. libxml_use_internal_errors($prevValue);
  26. }
  27. }