I am getting below error when switched Magento2 site to developer mode, spent couple of hours looking at xml files and couldn't find one that has issues. I know that one or morexml file(s) have some unwanted characters somewhere but Magento will not give any clues about other than pointing to multiple line numbers in the merged xml that's generated at run time, with the same validation error.

Character content other than whitespace is not allowed because the content type is 'element-only'

Did anyone run into similar issue since it's not specific to out of box or 3rd party extensions, and based on what I read this can happen to custom extensions as well.

1 Answer 1


I would like to update to give details on the fix to help others since I saw many posts that are specific to a custom extension or a 3rd party extension, but nothing generic to find and fix root cause for any extensions and other XML files that may used in di-compile/merge process. I am positive that will approach will identify any XML valuation errors since all XML files are validated against respective schema files when the site is in developer mode.

First hint was from Alan Strom's post here. I used similar code for the most part but it didn't work in Magento 2.3.4 version Dom.php, so had to change the code and function location as well to make it work.

2nd clue is from a PHP post on SO here.

Working code sample that will save merged xml file to root of your site(/var/www/html/<my_site>) so that you can look at the line numbers pointed in the errors to identify the root cause within minutes. This will work for any out of box, or 3rd party extension code as well.

Add this code to your version of Dom.php in

public static function validateDomDocument(\DOMDocument $dom, $schema, $errorFormat = self::ERROR_FORMAT_DEFAULT) function before the return statement.

    if(count($errors) > 0) {

Make sure to comment/document any changes not to lose during upgrade and repeating this issue all over again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.