How to fix the «Character content other than whitespace is not allowed» XML DOM error?

Set a breakpoint to the following line of the \Magento\Framework\Config\Dom::_initDom method:

Then analyse the problem document.
In my case, the error was caused by the following incorrect code:

02

“How to analyse the problem document.”

Printing out $dom is printing everything. Can’t identify file with the issue. Using M2.2.6.

Thank you.

Got it by checking value of $xml.

You’re awesome!! Thanks for this website.