hyperized/xml-validator

A simple PHP XML validator

1.4.1 2020-01-28 15:59 UTC

This package is auto-updated.

Last update: 2024-04-08 20:15:21 UTC


README

Buy us a tree Run tests Scrutinizer Code Quality Code Coverage FOSSA Status License

A simple PHP XML validator.

Installation

composer require hyperized/xml-validator

Usage

<?php

namespace Hyperized\Xml;

require __DIR__ . '/vendor/autoload.php';

$xmlString = file_get_contents(__DIR__ . '/tests/files/correct.xml');
$dirtyXMLString = file_get_contents(__DIR__ . '/tests/files/incorrect.xml');
$xmlFile = __DIR__ . '/tests/files/correct.xml';
$xsdFile = __DIR__ . '/tests/files/simple.xsd';

$validator = new Validator();

// String validation
print_r($validator->isXMLStringValid($xmlString)); // 1
print_r($validator->isXMLStringValid($xmlString, $xsdFile)); // 1

// File validation
print_r($validator->isXMLFileValid($xmlFile)); // 1
print_r($validator->isXMLFileValid($xmlFile, $xsdFile)); // 1

// Error handling
try {
    $validator->isXMLStringValid($dirtyXMLString, $xsdFile);
} catch (Exceptions\InvalidXmlException $exception)
{
    print_r($exception->getMessage()); //  xmlParseEntityRef: no name\n The document has no document element.
}

Treeware

You're free to use this package, but if it makes it to your production environment you are required to buy the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you support this package and contribute to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees here offset.earth/treeware

Read more about Treeware at treeware.earth

License

FOSSA Status