novomirskoy/xml-validator
最新稳定版本:0.0.2
Composer 安装命令:
composer require novomirskoy/xml-validator
包简介
README 文档
README
XML document validation using XSD schemas
Installation
Install the library using Composer:
composer require novomirskoy/xml-validator
Requirements
The following PHP extensions are required for the library to work:
ext-domext-libxml
Usage
Create an instance of the Validator class and call the validate() method,
passing an XML document as a string and a schema. The schema can be either a string or a path to an XSD file.
Create a schema instance using the named constructors Schema::file()
or Schema::string(), passing the file path or schema string respectively.
The validator does not store the validation result, so it immediately returns a Result object that indicates whether the validation was successful and returns a list of all errors that occurred.
Examples
// Example XML document $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <book> <title>Design Patterns</title> <author>Gamma</author> <year>1994</year> </book> XML; // Validation using XSD schema from string $xsdSchema = <<<XSD <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="book"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="author" type="xs:string"/> <xs:element name="year" type="xs:integer"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> XSD; $result = new Validator()->validate( xml: $xml, schema: Schema::string($xsdSchema), ); if (!$result->isValid()) { foreach ($result->errors as $error) { echo $error, PHP_EOL; } } // Validation using XSD schema from file $result = new Validator()->validate( xml: $xml, schema: Schema::file('/path/to/schema.xsd'), ); if (!$result->isValid()) { foreach ($result->errors as $error) { echo $error, PHP_EOL; } }
Documentation
For the full documentation in Russian, please see docs/README.ru.md.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2026-05-12