Recent Posts


Magento 2 XML Validation Errors


Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

Magento 2 validates most, if not all, of its XML configuration files via a schema document. If you’re dealing with someone else’s code and you need to jump to the source of a schema problems, here’s a debugging snippet.

#File: vendor/magento/framework/Config/Dom.php
public function validate($schemaFileName, &$errors = [])
    if ($this->validationState->isValidationRequired()) {
        $errors = $this->validateDomDocument($this->dom, $schemaFileName, $this->errorFormat);
        //start debug
        if(count($errors) > 0)
            header('Content-Type: text/plain');
        //end debug            
        return !count($errors);
    return true;

Magento 2 validates the merged dom tree – this will output the error, the schema file that’s being violated, and the entire merged tree. With this, you should be able to pinpoint the problem node, and from there search your codebase for the incorrect XML file.

Copyright © Alan Storm 1975 – 2022 All Rights Reserved

Originally Posted: 16th March 2016