werd/xml-xpath-validation

基于XML XPath的验证

1.2.0 2015-09-22 18:59 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:16:18 UTC


README

基于XML XPath的验证

Latest Stable Version Build Status Coverage Status Dependency Status License

功能

  • 基于正则表达式的验证,带有元素计数验证
  • 兼容PHP >= 5.5 和 HHVM

安装

通过Composer

$ composer require werd/xml-xpath-validation

使用方法

use Werd\XmlXpathValidation\Validator;
use Werd\XmlXpathValidation\RulableInterface;

class MyRules implements RulableInterface
{
    public function getRules()
    {
        return [
            [
                'xpath' => '//my-node/@my-attribute',
                'regex' => self::REGEX_INTEGER
            ],
            [
                'xpath' => '//my-node/sub-node',
                'regex' => '/^some-custom:+[a-z]+$/i',
            ],
            ...
        ];
    }
}

$myRules = new MyRules();
$validator = new Validator();
$result = $validator->validate($pathToXml, $myRules->getRules());