12

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

18

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
    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 – open-ecommerce.org Dec 19 '17 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. – Hari Swaminathan Jan 25 '18 at 8:27
  • Any ideas on how to output the filename of the corrupt xml? – David Lambauer Feb 23 '18 at 20:53
  • Installing the Mageplaza core fixed this issue for me: github.com/mageplaza/module-core – seanbreeden Nov 8 '18 at 15:46
22

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.

  • 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 '18 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 '18 at 10:00
  • 1
    You are a true hero – Pablo Mar 2 at 13:01
6

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.

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.