0

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.

asked Feb 23, 2020 at 1:49

1 Answer 1

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) {
 var_dump($errors);
 var_dump("schema_name");
 var_dump($schema);
 $dom->save('merged_xml_file.xml');
 exit;
 }

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

answered Feb 23, 2020 at 2:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.