13

I've received that message below when I try to reset my admin password using the Admin panel, I've my custom module installed.

I see this same message on a white screen when I try to access using the tab created in System > Configuration.

Message:

Invalid XML in file /var/www/html/rmiorder/app/code/Vendor/Hosebuilder/etc/email_templates.xml: Element 'config': Character content other than whitespace is not allowed because the content type is 'element-only'. Line: 2

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

File XML:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
    <template id="vendor_hosebuilder_section_general_show_email_template" label="Hose email template for requesting quote" file="hose_request_email_template.html" type="html" module="Vendor_Hosebuilder" area="frontend"/>
</config>

How can I solve that issue?

5 Answers 5

27

This problem you got because the XML code, you copy directly on internet/webpage, there is some hidden character before start each line. This isn't space/ newline character. So, when push to Magento, Magento doesn't know this character, and it shows errors as your message. Solutions: clear all space between tag and order again.

3
  • Perfect answer solved my issue as well Jul 24, 2018 at 12:01
  • Yes, removing all tags solves the problem. Oct 2, 2020 at 5:16
  • I copied some xml code from some site, and this issue rose.. it was this answer that saved my time. I couldn't see the characters but deleting all spaces/invisible characters before actual code in every line solved my problem. Thanks, Upvoted!
    – MSQ
    May 5, 2021 at 11:17
1

Check the all and tags in the top of your module files, like theses:

etc/frontend/routes.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">

etc/email_templates.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">

etc/module.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">

view/frontend/layout/vendor_hosebuilder_index_index.xml

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="1column">
1

enter image description here

That was the issue in my case. Their was no way to find in large set of files. debugging steps: open file:

  1. vendor/magento/framework/View/Model/Layout/Update/Validator.php in function public function isValid dump/echo $value in catch and get complete combined layout file in which you are facing issue.
  2. use some editor to found special character.

OR

other way can be open all files in your custom modules related to handler on whcih you are facing issue, like I was facing issue on catalog_product_view page you can see issue in all catalog_product_view.xml files

0

When the error is caused by a layout file, this article explains how to find the exact file causing the error

https://softomars.com/2020/12/22/magento-2-exception-character-content-other-than-whitespace-is-not-allowed-because-the-content-type-is-element-only/

0

In my case the reason was "preference" had no content, i changed from this

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <preference for="Magento\Wishlist\Controller\Index\Add"
         type="Example\Wishlist\Controller\Index\Add">
        </preference>
</config>

to this

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Wishlist\Controller\Index\Add" type="Example\Wishlist\Controller\Index\Add"/>
</config>

Your Answer

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

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