greenter/ubl-validator
Validate OASIS UBL XML documents against the correct XSD via UBLVersionID. Provide XML content, run isValid(), and get validation errors. Supports custom XSD base directories to validate multiple UBL versions (e.g., 2.1/2.2).
OASIS Universal Business Language (UBL) Schema Validator.
Via Composer from packagist.org.
composer require greenter/ubl-validator
Simple usage.
use Greenter\Ubl\UblValidator;
$xml = file_get_contents('20000000001-01-F001-1.xml');
$validator = new UblValidator();
if ($validator->isValid($xml)) {
echo 'Success!!!';
} else {
echo $validator->getError();
}
Above example follows next steps:
<cbc:UBLVersionID>XSD file in base directoryschemaValidate and gets resultThis package not include all UBL xsd, but you can add others xsd directory and use other UBL version.
use Greenter\Ubl\UblValidator;
use Greenter\Ubl\Resolver\UblPathResolver;
$ubl = new UblValidator();
$ubl->pathResolver = new UblPathResolver();
$ubl->pathResolver->baseDirectory = './my-ubl-xsd';
echo $ubl->isValid('<Invoice ...>');
/my-ubl-xsd directory follows this structure:
\my-ubl-xsd
│
├─2.1/
│ ├─ common/
│ └─ maindoc/
│
├─2.2/
│ ├─ common/
│ └─ maindoc/
You can download UBL xsd from oasis-open
How can I help you explore Laravel packages today?