20

I am trying to upgrade a website from Magento 2.1.8 to 2.2.0

I have configured composer for 2.2.0 and also updated it with command line.

Now when I run magento setup:upgrade its halt on running schema and showing following note: pfa for more info.

Running schema recurring...Invalid Document Element 'resource': The attribute 'title' is required but missing. Line: 12

Element 'resource': The attribute 'title' is required but missing. Line: 13

enter image description here

1

6 Answers 6

24

My best guess is that you have a <resource>-tag in any etc/acl.xml-file with a missing title-attribute. Usually this would throw the issue that you could not create or edit a new role. I'm guessing that they created an extra check in 2.2 to detect this more earlier.

Better check the acl.xml-files of your own custom extensions and/or those of 3rd party extensions. Please note: the title-attribute is only required for new <resource>-nodes. So if your adding a new resource-node to an existing resource node (provided by another module) there is no need to add the title-attribute to those. For example:

<!-- provided by Magento_Backend, so they already have a title: -->
<resource id="Magento_Backend::stores">
    <resource id="Magento_Backend::stores_settings">
        <!-- provided by Magento_Config: -->
        <resource id="Magento_Config::config">
            <!-- New resource! Title is required: -->
            <resource id="Vendor_Module::config_general" title="Something" translate="title"/> 
        </resource>
    </resource>
</resource>
4
  • 5
    some times this can happens when you are using a module that depends in other kind of parent module like a megaplaza core, and the parent module is not installed Dec 19, 2017 at 14:52
  • 1
    I am also having the same issue, but unfortunately I was not able to find the etc/acl.xml file with missing title attribute, I have checked all custom extensions. Is there some way I can spot the file easily. Jan 25, 2018 at 8:27
  • Any ideas on how to output the filename of the corrupt xml? Feb 23, 2018 at 20:53
  • Installing the Mageplaza core fixed this issue for me: github.com/mageplaza/module-core Nov 8, 2018 at 15:46
69

To find the file with the missing attribute you can modify the following file

vendor/magento/framework/Config/Reader/Filesystem.php

add following code

foreach($configMerger->getDom()->getElementsByTagName('resource') as $element ){
    if (!$element->hasAttribute('title')) {
        var_dump($configMerger->getDom()->saveXML($element));
    }
}

to the method

protected function _readFiles($fileList)

so it should look like

protected function _readFiles($fileList)
{
    /** @var \Magento\Framework\Config\Dom $configMerger */
    $configMerger = null;
    foreach ($fileList as $key => $content) {
        try {
            if (!$configMerger) {
                $configMerger = $this->_createConfigMerger($this->_domDocumentClass, $content);
            } else {
                $configMerger->merge($content);
            }
        } catch (\Magento\Framework\Config\Dom\ValidationException $e) {
            throw new \Magento\Framework\Exception\LocalizedException(
                new \Magento\Framework\Phrase("Invalid XML in file %1:\n%2", [$key, $e->getMessage()])
            );
        }
    }
    if ($this->validationState->isValidationRequired()) {
        $errors = [];
        if ($configMerger && !$configMerger->validate($this->_schemaFile, $errors)) {
            foreach($configMerger->getDom()->getElementsByTagName('resource') as $element ){
                if (!$element->hasAttribute('title')) {
                    var_dump($configMerger->getDom()->saveXML($element));
                }
            }
            $message = "Invalid Document \n";
            throw new \Magento\Framework\Exception\LocalizedException(
                new \Magento\Framework\Phrase($message . implode("\n", $errors))
            );
        }
    }

    $output = [];
    if ($configMerger) {
        $output = $this->_converter->convert($configMerger->getDom());
    }
    return $output;
}

Now you will be able to see a dump of the wrong XML element.

9
  • 2
    Ah perfect, your solution saved me tons of time.. we're using a lot of third party extensions in our store :)
    – Xaiamedia
    May 9, 2018 at 8:20
  • 1
    Perfect, you saved my time :) One of the 3rd party modules was referring a resource which wasn't defined.
    – Nidheesh
    Aug 29, 2018 at 10:00
  • 1
    You are a true hero
    – Pablo
    Mar 2, 2019 at 13:01
  • 2
    Amazing! You should work in Magento and help them sort this giant mess out ;)
    – Roy Toledo
    Aug 20, 2020 at 20:18
  • 1
    Be careful, I upgraded my magento to 2.4.0v and I waste a lot of time trying to find one of my acl.xml files. At the end, the problem was in vendor/magento/module-inventory-in-store-pickup-api/etc/acl.xml Sep 17, 2020 at 1:09
17

I had this same problem recently. A couple of observations and a workaround.

1) It would help immensely if instead of 'Invalid Document' it told you which document was invalid.

2) The setup:upgrade process should probably do some pre-flight checks to make sure it can do the upgrade.

Anyway, if you're stuck trying to find a missing title in the dozens of acl.xml files, but need to get a site back online quick, the quick workaround is to make the title attribute optional instead of required.

Edit vendor/magento/framework/Acl/etc/acl_merged.xsd

Find the line

<xs:attribute name="title" type="typeTitle" use="required" />

replace with

<xs:attribute name="title" type="typeTitle" use="optional" />

re-run magento setup:upgrade

You'll still need to find the plugin with the missing title at some point.

3
  • That fixed it right up. A million thankyous!!
    – Roy Toledo
    Aug 20, 2020 at 20:30
  • I have spent all morning on this !! you are a legend Nov 2, 2020 at 13:00
  • Useful for a quick fix on a local box
    – Joel Davey
    Aug 24, 2021 at 10:32
2

Thanks, @DimaPortenko, @GielBerkers and @ShaunMurray

You save lots of time to find an error in my ACL file.

After upgrade Magento 2.3.4 to 2.4.2 I was facing this error on admin login. error in acl syntex

by putting @DimaPortenko code at

vendor\magento\framework\Config\Reader\Filesystem.php

I found the wrong acl.xml file easily.

foreach($configMerger->getDom()->getElementsByTagName('resource') as $element ){
    if (!$element->hasAttribute('title')) {
        var_dump($configMerger->getDom()->saveXML($element));
    }
}

By using this command you can easily find the file find.

grep -Rn 'resource id="MSP_SecuritySuite::config"' ./ --include=acl.xml

enter image description here

Thank you.

0

I have changed the "Adminhtml" to "Backend" in below code then it works.

Resource tag Before change :

**<resource id="Magento_Adminhtml::admin">**

Resource tag After change :

**<resource id="Magento_Backend::admin">**

Final code as below.

**

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Neo_Testing::testing" title="testing" sortOrder="100"/>
            </resource>
        </resources>
    </acl>
</config>

**

0

Invalid Document Element resource The attribute title is required in Magento 2x

enter image description here

It't is working,

http://code.wewebtech.com/invalid-document-element-resource-the-attribute-title-is-required-in-magento-2x/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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