Is there a way to do XSD validation of an XML stream in PHP
-
05-07-2019 - |
Question
Let's say I want to be able to validate that a 50GB+ XML file conforms to a given XSD. I could use
DOMDocument::load & DOMDocument::schemaValidate
but that will take all of time on loading and will generally exhaust all available memory for me. Is there any way to feed an XSD to a SAX or any other type of stream processor and have it verify that all is well?
Solution
You may use XMLReader:
$reader = new XMLReader();
$reader->open('xmlfile.xml');
$reader->setSchema('schemafile.xsd');
while($reader->read());
$reader->close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow