Skip to content

webstasolutions/xml-validator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Xml validator

Build Status Packagist

Validate Xml against a xsd schema file.

Installation

Library

$ git clone https://github.com/seromenho/XmlValidator.git

Composer

$ composer require seromenho/xml-validator:dev-master

Usage

<?php
require "./vendor/autoload.php";
use XmlValidator\XmlValidator;

$xml = "<sample>my xml string</sample>";
$xsd = "path_to_xsd_file.xsd";

// Validate
$xmlValidator = new XmlValidator($xml, $xsd);
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
}

Based on XmlUtils from Symfony config component.

About

Validates XML against a schema.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%