Unfortunately, XMLReader did not confirm many things in my case.
Here is a small piece of the class that I wrote some time ago:
class XmlValidator { public function isXMLFileValid($xmlFilename, $version = '1.0', $encoding = 'utf-8') { $xmlContent = file_get_contents($xmlFilename); return $this->isXMLContentValid($xmlContent, $version, $encoding); } public function isXMLContentValid($xmlContent, $version = '1.0', $encoding = 'utf-8') { if (trim($xmlContent) == '') { return false; } libxml_use_internal_errors(true); $doc = new DOMDocument($version, $encoding); $doc->loadXML($xmlContent); $errors = libxml_get_errors(); libxml_clear_errors(); return empty($errors); } }
It works great with streams and vfsStream , as well as for testing purposes.
source share