ottosmops/xmlvalidator

Validate XML-Files, also parts

v1.7.0 2023-07-17 07:53 UTC

This package is auto-updated.

Last update: 2024-04-17 09:29:37 UTC


README

Software License Tests Packagist Downloads

This package was developed to validate Mets files for the DFG-Viewer. It is possible to validate only parts of a xml-file. Validation is possible with xsd, rng and xsl (Schematron). To validate only parts of an XML file, specify the root element of that part. In the tests folder is a copy of dmj/dfgviewer-schema.

Installation

composer require ottosmops/xmlvalidator

Usage

There is the one and only method validate:

<?php

require('vendor/autoload.php');

use Ottosmops\XmlValidator\XmlValidator;

class test {
    public static function index() {
        $option = ['file'   => 'tests/data/valid/mets_001.xml',
                    'ns'     => 'mets',
                    'nsuri'  => 'https://www.loc.gov/METS/',
                    'root'   => 'mets',
                    'schema' => 'https://www.loc.gov/standards/mets/mets.xsd'];

        $validator = new XmlValidator($option);
        if (!$validator->validate()) {
            print("validated mets: is not valid".PHP_EOL);
            print($validator->getErrors());
        } else {
            print("validated mets: is valid".PHP_EOL);
        }
    }
}

test::index();

You can find more examples in the tests folder.

License

The MIT License (MIT). Please see License File for more information.