werd/xml-xpath-validation

XML XPath based validation

1.2.0 2015-09-22 18:59 UTC

This package is not auto-updated.

Last update: 2024-04-27 15:15:18 UTC


README

XML XPath based validation

Latest Stable Version Build Status Coverage Status Dependency Status License

Features

  • Regex based validation with element count validation
  • Compatible with PHP >= 5.5 and HHVM

Installation

Through Composer:

$ composer require werd/xml-xpath-validation

Usage

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());