Download the PHP package hyperized/xml-validator without Composer

On this page you can find all versions of the php package hyperized/xml-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package xml-validator

hyperized/xml-validator

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

A simple PHP XML validator.

Installation

Package PHP Notes
2.x ^8.3 Current. Requires ext-dom and ext-libxml
1.x >=7.2 Unmaintained. See Migrating from 1.x

Usage

Validate a document and report why it failed:

The schema is optional, and a document you already hold in memory goes through validateXMLString() instead. Both return void and throw on failure:

Exceptions

Every exception this package throws implements XmlValidatorException, so one catch block covers all of them and keeps working when a new one is added.

Exception Thrown when
FileDoesNotExist No file at the given XML or XSD path
FileCouldNotBeOpenedException The path exists but reading it failed
EmptyFile The XML file holds nothing
InvalidXml Malformed, empty once trimmed, or rejected by the schema

All four extend RuntimeException.

InvalidXml::getErrors() returns libxml's own LibXMLError objects, so line, column and level survive. getMessage() is a newline-joined summary of the same errors, which is usually what you want in a log line.

When you only need yes or no

The is*Valid() predicates run the same check, catch the exceptions above and return false instead. They never throw:

Because they are implemented on top of the throwing methods, the two forms can never disagree. Reach for these when a failure needs no explanation; reach for validate*() when it does.

Dependency injection

Validator implements ValidatorInterface, which declares all eight public methods. Type-hint against the interface where you inject or mock it:

No error state is kept between calls, so an instance is safe to reuse and to share, including as a container singleton. The only mutable state is the document version and encoding covered below.

Document version and encoding

DOMDocument is constructed with an XML version of 1.0 and an encoding of utf-8. Prefer setting them once, at construction:

setVersion() and setEncoding() exist too, but they mutate the instance. On a validator you have shared, that change is visible to every other caller, so reach for the constructor instead.

Untrusted input

libxml does not resolve external entities and caps internal entity expansion, so SYSTEM references are not fetched and expansion bombs are rejected rather than exhausting memory. That protection comes from libxml's defaults rather than from this package, and this package does not weaken them: LIBXML_NOENT is never passed.

Schema paths are a different matter. validateXMLFile() and validateXMLString() both read the XSD from the path you give them, so that path should come from your own configuration and never from a request.

Migrating from 1.x

2.0 replaces the error-reporting API. The old throwError() could not report failures from isXMLStringValid() at all, and raised a fatal Error: Typed property ... must not be accessed before initialization when nothing had failed yet.

1.x 2.0
$validator->throwError() Catch from validateXMLFile() / validateXMLString()
catch (EmptyFile \| FileDoesNotExist \| ...) catch (XmlValidatorException)
Exceptions extend Exception Exceptions extend RuntimeException
Error message string only InvalidXml::getErrors() with line and column

Also in 2.0:

Development

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


All versions of xml-validator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-dom Version *
ext-libxml Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hyperized/xml-validator contains the following files

Loading the files please wait ...