Conditions | 4 |
Paths | 4 |
Total Lines | 20 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | public static function isValid($xml, $xsd) |
||
15 | { |
||
16 | if (!self::isXML($xml)) { |
||
17 | throw new \Exception('XML invalid'); |
||
18 | } |
||
19 | libxml_use_internal_errors(true); |
||
20 | libxml_clear_errors(); |
||
21 | $dom = new \DOMDocument('1.0', 'utf-8'); |
||
22 | $dom->preserveWhiteSpace = false; |
||
23 | $dom->formatOutput = false; |
||
24 | $dom->loadXML($xml, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG); |
||
25 | libxml_clear_errors(); |
||
26 | if (! $dom->schemaValidate($xsd)) { |
||
27 | $errors = []; |
||
28 | foreach (libxml_get_errors() as $error) { |
||
29 | $errors[] = $error->message; |
||
30 | } |
||
31 | throw new \Exception('Errors found: ' . implode(', ', $errors)); |
||
32 | } |
||
33 | return true; |
||
34 | } |
||
59 | } |