XML XPath based validation
- Regex based validation with element count validation
- Compatible with PHP >= 5.5 and HHVM
Through 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());