承接 novomirskoy/xml-validator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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-dom
  • ext-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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2026-05-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固