Skip to content

Latest commit

 

History

History
46 lines (40 loc) · 1.64 KB

README.md

File metadata and controls

46 lines (40 loc) · 1.64 KB

xml-xpath-validation

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