eclipxe/xmlschemavalidator
Composer 安装命令:
composer require eclipxe/xmlschemavalidator
包简介
PHP Library for XML Schema Validations
关键字:
README 文档
README
This is a library to validate XML files against multiple XSD Schemas according to its own definitions.
The way this works is:
- Receive a valid xml string as the content to be evaluated.
- Scan the file for every schemaLocation.
- Compose a schema that include all the schemas.
- Validate the XML against the composed file.
Installation
Use composer, so please run:
composer require eclipxe/xmlschemavalidator
Basic usage
<?php declare(strict_types=1); use Eclipxe\XmlSchemaValidator\SchemaValidator; $contents = file_get_contents('example.xml'); $validator = SchemaValidator::createFromString($contents); if (! $validator->validate()) { echo 'Found error: ' . $validator->getLastError(); }
Advanced usage
<?php declare(strict_types=1); use Eclipxe\XmlSchemaValidator\SchemaValidator; use Eclipxe\XmlSchemaValidator\Exceptions\ValidationFailException; use Eclipxe\XmlSchemaValidator\Internal\LibXmlException; // create SchemaValidator using a DOMDocument $document = new DOMDocument(); $document->load('example.xml'); $validator = new SchemaValidator($document); // change schemas collection to override the schema location of a specific namespace $schemas = $validator->buildSchemas(); $schemas->create('http://example.org/schemas/x1', './local-schemas/x1.xsd'); // validateWithSchemas does not return boolean, it throws an exception try { $validator->validateWithSchemas($schemas); } catch (ValidationFailException $ex) { echo 'Found error: ' . $ex->getMessage(); $previous = $ex->getPrevious(); if ($previous instanceof LibXmlException) { foreach ($previous->getErrors() as $libXmlError) { echo $libXmlError->message, PHP_EOL, 'File: ', $libXmlError->file, ':', $libXmlError->line, ',', $libXmlError->column, PHP_EOL; } } }
On previous example, the class LibXmlException is internal.
It will be public (not internal) on next major release.
Exceptions
This library creates its own specific exceptions and all of them implements XmlSchemaValidatorException.
Check the exceptions' documentation for more information.
When this library uses LibXML functions, it captures the errors and throw its own exception.
Version 1.x is deprecated
Version 1.x is no longer on development. It has a problem of concerns, the same library try to solve two different issues: Validate an XML file and store locally a copy of the XSD files. Version 2.x breaks this problem and give this library only one propose: Validate an XML file against its multiple XSD files, it does not matter where are located.
Version 2.x is deprecated
Migration changes between version 2 and version 3
Version 2.x was compatible with PHP 7 and was deprecated on 2020-04-05.
A branch 2.x has been created, it might be installable using composer require eclipxe/xmlschemavalidator:2.x-dev,
but it will not be active maintained. You should change your dependency as soon as possible.
Contributing
Contributions are welcome! Please read CONTRIBUTING for details and don't forget to take a look in TODO and CHANGELOG files.
Copyright and License
The eclipxe/XmlSchemaValidator library is copyright © Carlos C Soto
and licensed for use under the MIT License (MIT). Please see LICENSE for more information.
eclipxe/xmlschemavalidator 适用场景与选型建议
eclipxe/xmlschemavalidator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 325.4k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2016 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xml」 「validation」 「xsd」 「xmlschema」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eclipxe/xmlschemavalidator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eclipxe/xmlschemavalidator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eclipxe/xmlschemavalidator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Load DOM document safety
Convert XSD (XML Schema) definitions into PHP classes
Adds request-parameter validation to the SLIM 3.x PHP framework
XSD schema validation constraint for PHPUnit
A jQuery augmented PHP library for creating and validating HTML forms
A Laravel validator for delimiter-separated list of emails.
统计信息
- 总下载量: 325.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 29
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-20