0

I am getting following error after upgrading magento 2.1 to 2.2.3

1 exception(s):
Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'file': This element is not expected.
Line: 1


Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'file': This element is not expected.
Line: 1

#0 /home/hardik/public_html/vendor/magento/framework/Config/Dom.php(115): Magento\Framework\Config\Dom->_initDom('<layout xmlns:x...')
#1 /home/hardik/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(111): Magento\Framework\Config\Dom->__construct('<layout xmlns:x...', Object(Magento\Framework\App\Arguments\ValidationState), Array, NULL, '/home/hardik/p...', '%message%\nLine:...')
#2 /home/hardik/public_html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(66): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Magento\\Framewo...', Array)
#3 /home/hardik/public_html/vendor/magento/framework/ObjectManager/ObjectManager.php(56): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\\Framewo...', Array)
#4 /home/hardik/public_html/vendor/magento/framework/Config/DomFactory.php(42): Magento\Framework\ObjectManager\ObjectManager->create('Magento\\Framewo...', Array)
#5 /home/hardik/public_html/vendor/magento/framework/View/Model/Layout/Update/Validator.php(141): Magento\Framework\Config\DomFactory->createDom(Array)
#6 /home/hardik/public_html/vendor/magento/framework/View/Model/Layout/Merge.php(461): Magento\Framework\View\Model\Layout\Update\Validator->isValid('<layout xmlns:x...', 'layout_merged', false)
#7 /home/hardik/public_html/vendor/magento/framework/View/Model/Layout/Merge.php(442): Magento\Framework\View\Model\Layout\Merge->_validateMergedLayout('LAYOUT_frontend...', '<file>/home/bik...')
#8 /home/hardik/public_html/generated/code/Magento/Framework/View/Model/Layout/Merge/Interceptor.php(193): Magento\Framework\View\Model\Layout\Merge->load(Array)
#9 /home/hardik/public_html/vendor/magento/framework/View/Layout/Builder.php(86): Magento\Framework\View\Model\Layout\Merge\Interceptor->load()
#10 /home/hardik/public_html/vendor/magento/framework/View/Layout/Builder.php(63): Magento\Framework\View\Layout\Builder->loadLayoutUpdates()
#11 /home/hardik/public_html/vendor/magento/framework/View/Page/Config.php(197): Magento\Framework\View\Layout\Builder->build()
#12 /home/hardik/public_html/vendor/magento/framework/View/Page/Config.php(207): Magento\Framework\View\Page\Config->build()
#13 /home/hardik/public_html/vendor/magento/framework/View/Result/Page.php(241): Magento\Framework\View\Page\Config->publicBuild()
#14 /home/hardik/public_html/vendor/magento/framework/View/Result/Layout.php(170): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#15 /home/hardik/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#16 /home/hardik/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#17 /home/hardik/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#18 /home/hardik/public_html/generated/code/Magento/Framework/View/Result/Page/Interceptor.php(130): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#19 /home/hardik/public_html/vendor/magento/framework/App/Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#20 /home/hardik/public_html/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\Framework\App\Http->launch()
#21 /home/hardik/public_html/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http\Interceptor->launch()
#22 /home/hardik/public_html/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#23 {main}

I am not getting how i can debug in which xml file there is issue.

Update: Now i can see 2 xml file after adding Langley's debug code. may be there is issue in these two file.

default.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="css/developer.css"/>
    </head>
    <body>
        <referenceBlock name="head.additional">
            <block class="Magento\Framework\View\Element\Template" name="config.theme.setting" template="Magento_Theme::html/config.phtml"/>
            <block class="Magento\Framework\View\Element\Template" name="theme.color.setting" template="Magento_Theme::html/theme_color.phtml"/>
        </referenceBlock>
        <referenceContainer name="header.container">
            <container name="header.panel.wrapper" htmlClass="panel wrapper" htmlTag="div" before="-"/>
            <block class="Magento\Theme\Block\Html\Header" name="header.content" template="html/header.phtml">
                <container name="toplinks-header" label="Header Links" as="toplinks-header" htmlTag="div" htmlClass="toplinks-wrapper"/>
                <container name="navigation-header" label="Navigation" as="navigation-header" htmlTag="div" htmlClass="navigation-wrapper"/>

                <container name="navigation-header-megamenu" label="Megamenu" as="navigation-header-megamenu" htmlTag="div" htmlClass="navigation-megamenu-wrapper">
                    <block class="Sm\MegaMenu\Block\MegaMenu\View" name="megamenu.topnav" as="megamenu_topnav" template="Sm_MegaMenu::megamenu.phtml" />
                </container>

                <container name="navigation.mobile">
                    <block class="Magento\Theme\Block\Html\Topmenu" name="nav.mobile" template="html/nav-mobile.phtml"/>
                </container>


                <container name="language-header" label="Language" as="language-header" htmlTag="div" htmlClass="language-wrapper"/>
                <container name="currency-header" label="Currency" as="currency-header" htmlTag="div" htmlClass="currency-wrapper"/>
                <container name="logo-header" label="Search" as="logo-header" htmlTag="div" htmlClass="logo-wrapper"/>
                <container name="search-header" label="Search" as="search-header" htmlTag="div" htmlClass="search-wrapper">
                    <block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml" />
                </container>
                <container name="cart-header" label="Mini Cart" as="cart-header" htmlTag="div" htmlClass="cart-wrapper"/>               
            </block>
        </referenceContainer>


        <referenceBlock name="header" remove="true"/>       
        <referenceContainer name="header.panel" remove="true"/>
        <referenceBlock name="navigation.sections" remove="true"/>
        <referenceBlock name="register-link" remove="true"/>
        <referenceBlock name="sale.reorder.sidebar" remove="true"/>
        <referenceBlock name="wishlist_sidebar" remove="true"/>

        <move element="top.links" destination="toplinks-header" after="-"/>
        <move element="logo" destination="logo-header" before="-"/>
        <move element="catalog.topnav" destination="navigation-header"/>
        <move element="currency" destination="currency-header"/>
        <move element="store.settings.language" destination="language-header"/>
        <move element="minicart" destination="cart-header"/>

        <!--add to sidebar-->
        <referenceContainer name="sidebar.additional">
            <!--<remove name="catalog.compare.sidebar"/>-->
            <referenceBlock name="catalog.compare.sidebar" remove="true"/>
            <referenceContainer name="catalog.compare.sidebar" display="false" />
            <block class="Magento\Cms\Block\Block" name="product-sidebar">
                <arguments>
                    <argument name="block_id" xsi:type="string">product-sidebar</argument>
                </arguments>
            </block>

            <!-- <block class="Magento\Cms\Block\Block" name="image-sidebar">
                    <arguments>
                            <argument name="block_id" xsi:type="string">image-sidebar</argument>
                    </arguments>
            </block> -->
        </referenceContainer>



        <referenceContainer name="footer-container">
            <container name="footer" as="footer" label="Page Footer" htmlTag="div" htmlClass="footer footer-wrapper">
                <!--<remove name="form.subscribe"/>
                <remove name="report.bugs"/>-->
                <referenceBlock name="form.subscribe" remove="true"/>
                <referenceBlock name="report.bugs" remove="true"/>
                <block class="Magento\Theme\Block\Html\Footer" name="footer.content" template="html/footer.phtml"/>
            </container>
        </referenceContainer>
    </body>
</page>

default_head_blocks.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <!-- ADD JQUERY -->
        <meta name="x_ua_compatible" content="IE=edge"/>
        <script src="js/jquery-2.1.4.min.js"/>      
        <script src="js/bootstrap/bootstrap.min.js"/>
        <script src="js/owl.carousel.js"/>
        <script src="js/easyResponsiveTabs.js"/>
        <script src="js/ytc_theme.js"/>
        <!-- ADD CSS  -->
        <css src="css/styles-m.css" />
        <css src="css/styles-l.css" media="screen and (min-width: 768px)"/>
        <css src="css/print.css" media="print" />       
        <css src="css/yttheme.css" />

        <!-- <css src="css/css_hack.css" /> -->
    </head> 
    <body>
        <referenceContainer name="after.body.start">
            <block class="Magento\Framework\View\Element\Js\Components" name="head.components" as="components" template="Magento_Theme::js/components.phtml" before="-"/>
        </referenceContainer>
    </body>
</page>
1

You can take a look into the dom reader.

/home/hardik/public_html/vendor/magento/framework/Config/Dom.php

Inside _initDom($xml):382 you will see where this exception is thrown and you can print the problematic XML e.g.

/**
 * Create DOM document based on $xml parameter
 *
 * @param string $xml
 * @return \DOMDocument
 * @throws \Magento\Framework\Config\Dom\ValidationException
 */
protected function _initDom($xml)
{
    $dom = new \DOMDocument();
    $useErrors = libxml_use_internal_errors(true);
    $res = $dom->loadXML($xml);
    if (!$res) {
        $errors = self::getXmlErrors($this->errorFormat);
        libxml_use_internal_errors($useErrors);
        var_dump($xml);die();
        throw new \Magento\Framework\Config\Dom\ValidationException(implode("\n", $errors));
    }
    libxml_use_internal_errors($useErrors);
    if ($this->validationState->isValidationRequired() && $this->schema) {
        $errors = $this->validateDomDocument($dom, $this->schema, $this->errorFormat);
        if (count($errors)) {
            var_dump($xml);die();
            throw new \Magento\Framework\Config\Dom\ValidationException(implode("\n", $errors));
        }
    }
    return $dom;
}

After resolving the issue you should remove the debugging code.

EDIT:

I guess you could take a look into the stack trace

7 /home/hardik/public_html/vendor/magento/framework/View/Model/Layout/Merge.php(442): Magento\Framework\View\Model\Layout\Merge->_validateMergedLayout('LAYOUT_frontend...', '/home/bik...')

Look for '/home/bik' in your xml files.

  • Thanks, i can see the xml file. But not getting the issue exactly. Please check my updated question if you can see the error. – Hardik Jun 25 '18 at 13:17
  • See updated answe. – Langley Jun 25 '18 at 13:32
  • error returns short path of error file. this is the short path name. /home/bik.. – Hardik Jun 25 '18 at 13:33
  • The <file> tag before that seems suspicious. You can also look for <file in you xml files, there shouldn't be too many of them. – Langley Jun 25 '18 at 13:36
0

Some addition to @Langley answer on how to find culprit xml node.

Print xml using @Langley answer. This will print complete xml layout file.You may have to view page source (ctrl+u) to see xml in browser. Now go to the error you were getting before printing xml, error should give you exact line number, use that line number in printed xml to find culprit xml/node.

I was getting css element is not expected error and problem was in layout file which had css node without head so i changed it from

<css src....> 

to

 <head>
   <css src...>
 </head>

Hope it helps someone.

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.