Skip to content

jsakars/xml-xpath-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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