seromenho / xml-validator
验证您的 XML 是否与 xsd 架构文件相符。
v1.0
2015-06-24 08:47 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 4.7.*
This package is not auto-updated.
Last update: 2024-09-24 03:28:36 UTC
README
验证 XML 是否与 xsd 架构文件相符。
安装
库
$ git clone https://github.com/seromenho/XmlValidator.git
Composer
$ composer require seromenho/xml-validator:dev-master
使用方法
<?php require "./vendor/autoload.php"; use XmlValidator\XmlValidator; $xml = "<sample>my xml string</sample>"; $xsd = "path_to_xsd_file.xsd"; // Validate $xmlValidator = new XmlValidator($xml, $xsd); try{ $xmlValidator->validate($xml,$xsd); // Check if is valid if(!$xmlValidator->isValid()){ // Do whatever with the errors. foreach ($xmlValidator->errors as $error) { /*echo sprintf('[%s %s] %s (in %s - line %d, column %d)', $error->level, $error->code, $error->message, $error->file, $error->line, $error->column ); */ } } } catch (\InvalidArgumentException $e){ // catch InvalidArgumentException }
基于 Symfony 配置组件中的 XmlUtils。