PHP code example of werd / xml-xpath-validation
1. Go to this page and download the library: Download werd/xml-xpath-validation library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
werd / xml-xpath-validation example snippets
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());