vrbata/xml-validator
最新稳定版本:v2.0.1
Composer 安装命令:
composer require vrbata/xml-validator
包简介
Validates your XML against a xsd schema.
关键字:
README 文档
README
Validate Xml against a xsd schema.
Installation
Library
$ git clone https://github.com/vrbata/XmlValidator.git
Composer
$ composer require vrbata/xml-validator:dev-master
Usage
<?php require "./vendor/autoload.php"; use XmlValidator\XmlValidator; $xml = "<sample>my xml string</sample>"; $xsd = "path_to_xsd.xsd"; // Validate based on xsd file $xmlValidator = new XmlValidator($xml, $xsd, XsdSource::FILE); 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 } // Validate based on xsd as string $xmlValidator = new XmlValidator($xml, $xsd, XsdSource::STRING); 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 }
Based on XmlUtils from Symfony config component.
统计信息
- 总下载量: 327.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-05