1. Go to this page and download the library: Download vrbata/xml-validator 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/ */
vrbata / xml-validator example snippets
mlValidator\XmlValidator;
$xml = "<sample>my xml string</sample>";
$xsd = "path_to_xsd.xsd";
// Validate based on xsd file
$xmlValidator = new XmlValidator($xml, $xsd, XsdSource::FILE);
try{
$xmlValidator->validate($xml,$xsd);
// Check if is valid
if(!$xmlValidator->isValid()){
// Do whatever with the errors.
foreach ($xmlValidator->errors as $error) {
/*echo sprintf('[%s %s] %s (in %s - line %d, column %d)',
$error->level, $error->code, $error->message,
$error->file, $error->line, $error->column
); */
}
}
} catch (\InvalidArgumentException $e){
// catch InvalidArgumentException
}
// Validate based on xsd as string
$xmlValidator = new XmlValidator($xml, $xsd, XsdSource::STRING);
try{
$xmlValidator->validate($xml,$xsd);
// Check if is valid
if(!$xmlValidator->isValid()){
// Do whatever with the errors.
foreach ($xmlValidator->errors as $error) {
/*echo sprintf('[%s %s] %s (in %s - line %d, column %d)',
$error->level, $error->code, $error->message,
$error->file, $error->line, $error->column
); */
}
}
} catch (\InvalidArgumentException $e){
// catch InvalidArgumentException
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.